in reply to Re: matching patterns
in thread matching patterns

Gentle Sovixi,

Your pattern matches; good. May I offer some tips?

  1. Use the <code> tags to make your code easier to read. (I see you've updated it to do so; good.)
  2. Your pattern now would match the 1-char string 'N'. Is that really what you want?
  3. You're using capturing parenthesis, but not using the value.
  4. When matching single letters, the square brackets read more easily that the '|' in parens.
  5. Use the 'x' modifier to make your code more readable and commentable. Viz
if ( $value =~ m/^(?: [AN]+ # Either at least one A|N |[AN]* # or an A|N run (?: NP)? # Possibly interrupted by NP [AN]* ) N$/x ){ # With a terminal N. print "match: $value\n"; }
Something still looks suspicious to me. Your first pattern match is a choice between [AN]+ and [AN]*(NP)?[AN]*. That second choice can match the null string. Seems odd.

throop