October 2015
Intermediate to advanced
356 pages
7h 54m
English
| Tip 76 | 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:
| | 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 ...