in reply to Re^2: Understanding Regex
in thread Understanding Regex

good spotted an thanks Lotus1
was just partially my fault: the code was correct but, as i work on an unfriendly OS, i need to put double quotes around the argument.
So the actual command line became:
perl -MYAPE::Regex::Explain -e " print YAPE::Regex::Explain->new(qr/$A +RGV[0]/)->explain();" "^\s*[^\s\*=]+\s*="
with the right output:
The regular expression: (?-imsx:^\s*[^\s\*=]+\s*=) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- [^\s\*=]+ any character except: whitespace (\n, \r, \t, \f, and " "), '\*', '=' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- = '=' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
and the second one perl -MYAPE::Regex::Explain -e " print YAPE::Regex::Explain->new(qr/$ARGV[0]/)->explain();" "^\s*\w+\s*=" with his right output:
The regular expression: (?-imsx:^\s*\w+\s*=) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \w+ word characters (a-z, A-Z, 0-9, _) (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- \s* whitespace (\n, \r, \t, \f, and " ") (0 or more times (matching the most amount possible)) ---------------------------------------------------------------------- = '=' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------
For the OP the best was probably to highlight only the different part:
perl -MYAPE::Regex::Explain -e " print YAPE::Regex::Explain->new(qr/$A +RGV[0]/)->explain();" "[^\s\*=]" .. ---------------------------------------------------------------------- [^\s\*=] any character except: whitespace (\n, \r, \t, \f, and " "), '\*', '=' ---------------------------------------------------------------------- perl -MYAPE::Regex::Explain -e " print YAPE::Regex::Explain->new(qr/$A +RGV[0]/)->explain();" "\w" .. ---------------------------------------------------------------------- \w word characters (a-z, A-Z, 0-9, _) ----------------------------------------------------------------------


L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.