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


in reply to Regex word options

Input:
This line Transcribed, For David Jones # This line Arranged, For Mike Johnson (great) Terrible weather today
Program:
#!/bin/perl my $file='regex.txt'; my $work = do { local $/; open my $fh, "<", $file or die "could not open $file: $!"; <$fh>; }; while ($work =~ /(Transcribed|Arranged),\s+For\s+([\w\s]+)/g) { print "Match: $1 Person: $2\n"; }
Output:
Match: Transcribed Person: David Jones Match: Arranged Person: Mike Johnson
Comments:

The \b (word boundary) matches have been removed as they don't really do anything. Note that it looks for (Transcribed|Arranged) as suggested by other The code looks for normal alpha characters and spaces as a name, terminating on the first that doesn't match, but this can be easily changed