in reply to Need a Regular Expression that tests for words in different order and captures the values found.

my %words; ++$words{$_} for /\w+/g; for ( [qw( Fred Flinstone )], [qw( Barney Rubble )], [qw( Joe Rockhead )], ) { next if @$_ != grep $words{$_}, @$_; print("matched @$_\n"); }

Update: Oops, missed "captures the values beside the matching words". Fixed:

my %next_words; $next_words{$1} = $2; while /(\w+)\s+(?=\w+)/g; for ( [qw( Fred Flinstone )], [qw( Barney Rubble )], [qw( Joe Rockhead )], ) { next if @$_ != grep defined($next_words{$_}), @$_; print(join(' ', map "$_ $next_words{$_}", @$_), "\n"); }
  • Comment on Re: Need a Regular Expression that tests for words in different order and captures the values found.
  • Select or Download Code