in reply to Re: Regex to match multiple words in an email subject
in thread Regex to match multiple words in an email subject
print /(?:SSL|SSL Certificate|VASCO)/ ? "Match\n" : "No match\n";
Because the pattern is not anchored at either end the string 'SSL Certificate' will never match.
$ perl -le' my @strings = ( "SSL", "SSL Certificate", "VASCO", "something else", ); for ( @strings ) { print $1 if /(SSL|SSL Certificate|VASCO)/; } ' SSL SSL VASCO
With no anchors you need to put the longer strings first:
$ perl -le' my @strings = ( "SSL", "SSL Certificate", "VASCO", "something else", ); for ( @strings ) { print $1 if /(SSL Certificate|SSL|VASCO)/; } ' SSL SSL Certificate VASCO
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex to match multiple words in an email subject
by philipbailey (Curate) on Jan 07, 2011 at 09:58 UTC | |
by JavaFan (Canon) on Jan 07, 2011 at 12:36 UTC |