October 2012
346 pages
7h 40m
English
| Tip 75 | Use Parentheses to Capture Submatches |
When specifying a pattern, we can capture submatches and then reference them elsewhere. This feature is especially useful in combination with the substitute command, but it can also be used to define patterns where a word is repeated.
Take this excerpt of text:
| patterns/springtime.txt | |
| | I love Paris in the |
| | the springtime. |
Can you spot the grammatical error? It’s surprisingly hard to see because of a trick that our mind plays on us, but it should pop out with emphasis: “Paris in the the springtime.” When a line break separates two occurrences of the same word, our brain tends to ignore the duplicate. The effect is called a lexical illusion.[20]
Here’s a regular expression that matches duplicate ...
Read now
Unlock full access