1

I'm looking to match the following strings:

Complete this list for Dave by five Complete this list for Paul by five Complete this list for Adam by five 

Here is the regex I've tried:

*Complete\sthis\slist\sfor\sDave|Paul|Adam\sby\sfive* 

But in my regex checker, Paul is matched even if the rest of the string is excluded (not present).

I've also tried:

*Complete\sthis\slist\sfor\s\bDave|Paul|Adam\b\sby\sfive* 

But I still get a match with a single word 'Paul'.

Working in Perl regex, what would be the best way to capture all variations of the string in regex?

Thanks,

2
  • 3
    Group subpatterns: prefix(?:one|two|three)suffix Commented Oct 18, 2019 at 13:36
  • Here is an example of what you may want in Perl: perl -le 'print "Complete this list for Dave by five" =~ m{Complete \s+ this \s+ list \s+ for \s+ ( Dave | Paul | Adam ) \s+ by \s+ five}xms;' Prints: Dave Commented Oct 18, 2019 at 20:27

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.