I have an input string which is a directory address:
Example: ProgramFiles/Micro/Telephone
And I want to match it against a list of words very strictly:
Example: Tel|Tele|Telephone
I want to match against Telephone and not Tel. Right now my regex looks like this:
my( $output ) = ( $input =~ m/($list)/o );
The regex above will match against Tel. What can I do to fix it?
If you want a whole word match:
\bis a zero-width word boundary. Word boundary in this case means the transition from or to a word character. A word character (\w) is[0-9a-zA-Z_].If you simply want to match against the longest in a partial word match put the longest first. For example:
or