

The position in the regex is advanced to. The word boundary does not make the engine advance through the string. The word boundary \b matches at the > because it is preceded by B. However, because of the star, that’s perfectly fine. The first token in the regex is the literal. * ? to the string Testing bold italic text.

Let’s see how the regex engine applies the regex ] * >.

So \99 is a valid backreference if your regex has 99 capturing groups. Most regex flavors support up to 99 capturing groups and double-digit backreferences. ( ) x \1 x \1 matches axaxa, bxbxb and cxcxc. You can reuse the same backreference more than once. This can be very useful when modifying a complex regular expression. This means that non-capturing parentheses have another benefit: you can insert them into a regular expression without changing the numbers assigned to the backreferences. Skip parentheses that are part of other syntax such as non-capturing groups. The first parenthesis starts backreference number one, the second number two, etc. Count the opening parentheses of all the numbered capturing groups. To figure out the number of a particular backreference, scan the regular expression from left to right. It is simply the forward slash in the closing HTML tag that we are trying to match. \1 matches the exact same text that was matched by the first capturing group. (Since HTML tags are case insensitive, this regex requires case insensitive matching.) The backreference \1 (backslash one) references the first capturing group. This regex contains only one pair of parentheses, which capture the string matched by *. By putting the opening tag into a backreference, we can reuse the name of the tag for the closing tag. Suppose you want to match a pair of opening and closing HTML tags, and the text in between. Using Backreferences To Match The Same Text Againīackreferences match the same text as previously matched by a capturing group.
