Exercise

This or that

Searching one word is easy, right? But searching exactly two or three words, you could not do that with a plain old "Control + F" search. But with regular expressions you are now able to define a search pattern that achieves this. You can use the str_view() to see what your regular expression matches.

When you connect multiple words with a pipe operator | you will match both the thing that comes before the pipe and the thing after. And you're not limited to just two. You can also have three options connected with two pipes Hello Anna|Berta|Colin.

You can furthermore use parentheses to group certain words together, looking e.g. for Hello (Anna|Berta|Colin) will produce a different result than the pattern above. Try out both options and compare the results.

Instructions

100 XP
  • Create a pattern that searches for movies starting with "Finding " and followed by the words "Nemo", "Harmony" or "Dory".
  • Now create the same pattern but wrap the three possibilities in parentheses () to compare the results.
  • Choose the one of the two patterns that matches the full movie names "Finding Nemo", "Finding Harmony" and "Finding Dory" and pass it to the third str_match() call.