80 days ago · Tech · hide · Fediverse post

Quick Recap # In Part 6, we learned about alternation with |, grouping with parentheses, and non-capturing groups (?:...). We saw that parentheses serve double duty: grouping for quantifiers and capturing matched text. Now let’s dig into the capturing side. Parentheses Capture What They Match # When you use regular parentheses (...), the engine saves whatever text matched inside them. The first set of parentheses is group 1, the second is group 2, and so on. The numbering goes left to right based on the opening parenthesis. Backreferences: Matching the Same Text Again # A backreference like \1 means “whatever group 1 actually matched.” Not the same pattern. The same text. This is a subtle but important distinction. ( # Group 1: capture a word [[:alpha:]]+ # One or more letters ) [[:blank:]] # A space \1 # Backreference: the SAME text group 1 matched Compact: ([[:alpha:]]+) \1 MATCH THESE the the is is hello hello DO NOT MATCH THESE the cat is was hello world This is how you find…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town