l.frankline has asked for the wisdom of the Perl Monks concerning the following question:

Hi Perl Monks,

I have created a perl script relating to the regular expression.

My aim is to find other than the character range from

chr(1) to chr(126).

Please analyse the code and do the needful.

Thanks in advance.

Regards,

Franklin.

code here:

=========================================================== @char126 = (1..126); $r = 0; @mykeys = (); foreach $key (@char126) { $keyvalue = chr($key); $keyvalue = quotemeta($keyvalue); $mykeys[$r] = $keyvalue; $r++; } $mykeys = join ("|", @mykeys); $line = "This is search line some text some text Ä Å some text some te +xt"; while ($line !~s#$mykeys##) { $col = length($`); print "Line: $. Col. $col unknown entity - $&\n"; }

Edit g0n - added code tags

Replies are listed 'Best First'.
Re: problem in regular expression
by davido (Cardinal) on Sep 03, 2005 at 07:30 UTC

    It's easier than that... You should read perlrequick, perlretut, and perlre. ...it's a couple hours of reading, but as they say, "then you'll know."

    Here's an example of how easy it can be to detect ascii values above 126, using a regular expression:

    while( $string =~ m/([^\x01-\x7E]+)/g ) { print $1, "\n"; }

    Dave

      I would drop the + otherwise you will get into one group any multiple of characters above ASCII 126.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law