in reply to Re^3: Need a Regular Expression that tests for words in different order and captures the values found.
in thread Need a Regular Expression that tests for words in different order and captures the values found.
What would I do in case of hyphens?
You need to figure out a boundary condition, then define it as a regex.
For instance, in the case of (?=.*\bfred\s+(\w+)) (note the closing parenthesis, missing in your reply), the boundary condition is the \b word boundary assertion.
It might be defined
my $boundary = qr{ \b }xms;
and used (without the //x modifier) (untested)
(?=.*${boundary}fred\s+(\w+))
Now just change the definition of $boundary to fit your needs. For instance, if you wanted first names to follow anything that was not a word character and also not a hyphen, you might define (untested)
my $boundary = qr{ (?<! [\w-]) }xms;
|
|---|