Today I will show you two good ways of matching text.
Using regex placeholders
Using the pre_match & post_match methods
Let’s start with a blob of text. Lorem ipsum would do nicely.
Now let’s say we want to match the text between:
Lorem ipsum
and
Nunc vel tellus
We’ll use the regex approach and do this:
That’s easy enough. If we inspect this data we’ll see that it contains two matching sets. We can return those sets by addressing them in this way:
That’s nice. Now let’s review the data that pre_match and post_match would return.
The pre_match is empty as expected since we started matching the beginning of the string. The post_method on the other hand contains everything we haven’t match with our regex and is left in the string.