http://www.perlmonks.org?node_id=1001767


in reply to Regex word options

Not exactly as you stated the problem, but an extensible approach:

C:\>perl -E "my @work=(\"I Arranged a meet.\", \"Transcribe this\"); for $work(@work) { if ($work =~ /Transcribe||Arranged/) { say $work; } } I Arranged a meet. Transcribe this C:\>

The \b does nothing useful as you state your problem; alternation is better done with an ||, ("or"). Solving the captures as you need them is left as an exercise.

Replies are listed 'Best First'.
Re^2: Regex word options
by choroba (Cardinal) on Nov 01, 2012 at 09:11 UTC
    The || does not work inside a regular expression (well, it does, but it matches anything). Add some more testing strings. Use single| inside a regex, or use two regexes connected by ||.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Alas, I erred.

      The honorable choroba is correct; blame simple carelessness; intermittent, inadequate internet access in my second consecutive month on the road and my plain errror for the wrongful use of ||. As written above it should be a single Vbar; as choroba notes, it could also be written as:

      #!/usr/bin/perl use 5.10.0; my @work=("I Arranged a meet.", "Transcribe this", "Shud Not MATCH"); for $work(@work) { if (($work =~ /Transcribe/) || ($work =~ /Arranged/) ) { say $work; } }