perlpal has asked for the wisdom of the Perl Monks concerning the following question:
I chanced upon this discrepancy in pattern matching behavior. I don't understand the reason for which i seek assistance.
When using multiple alternation meta characters across multiple lines in a single regex , not all the patterns are correctly matched.
The code below does not work
#!/usr/software/bin/perl my $output = "Error: Illegal option -- x"; print "\nTRUE\n" if ( $output =~ /The.*?command\stakes.*?arguments;\syou\sgave.* |Illegal\soption.* |.*?is\snot\sa\svalid\soption.*/i );
whereas the same works when the alternation meta characters are in a single line
Baffled.#!/usr/software/bin/perl #my $output = `dfm event list -x`; my $output = "Error: Illegal option -- x"; print "\nTRUE\n" if ( $output =~ /The.*?command\stakes.*?arguments;\syou\sgave.*|Illegal\soption +.*|.*?is\snot\sa\svalid\soption.*/i );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Alternation metacharacter across multiple lines in regex not working
by Your Mother (Archbishop) on Mar 18, 2010 at 08:12 UTC | |
|
Re: Alternation metacharacter across multiple lines in regex not working
by GrandFather (Saint) on Mar 18, 2010 at 08:14 UTC |