Wrapping Up
We started this chapter by using the match method both to check whether a string matched a particular pattern and to extract capture groups from within that pattern. Then we explored the scan method on strings, and how we could use it to extract many different patterns from within a string.
As well as simply matching patterns, we discovered how to use sub and gsub to take portions of text that match a pattern and replace them with something else. We also covered gsub’s ability to take a block, and we used that to perform some further processing of the matched text before replacing it.
Next up, we’ll be looking at an alternative technique to regular expressions—parsers—and when they can be useful.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access