Question: How would you write a regex that matches a sentence where the first word is either Alice, Bob, or Carol; the second word is either
How would you write a regex that matches a sentence where the first word is either Alice, Bob, or Carol; the second word is either eats, pets, or throws; the third word is apples, cats, or baseballs; and the sentence ends with a period? This regex should be case-insensitive. It must match the following:
• 'Alice eats apples.'
• 'Bob pets cats.'
• 'Carol throws baseballs.'
• 'Alice throws Apples.'
• 'BOB EATS CATS.'
but not the following:
• 'RoboCop eats apples.'
• 'ALICE THROWS FOOTBALLS.'
• 'Carol eats 7 cats.'
Step by Step Solution
3.42 Rating (161 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
