![]() Double-digit backreferences \10 through \99 are supported by the JGsoft applications, Delphi, Python, and Boost. \1 through \9 are supported by the JGsoft applications, Delphi, Perl (though deprecated), Python, Ruby, PHP, R, Boost, and Tcl. The \1 syntax for backreferences in the replacement text is borrowed from the syntax for backreferences in the regular expression. Replacing *word* as a whole with word is far easier and far more efficient than trying to come up with a way to correctly replace the asterisks separately. This technique using backreferences is important to understand. Effectively, this search-and-replace replaces the asterisks with bold tags, leaving the word between the asterisks in place. The replacement text \1 replaces each regex match with the text stored by the capturing group between bold tags. As a simple example, the regex \* ( \w ) \* matches a single word between asterisks, storing the word in the first (and only) capturing group. This makes it possible to rearrange the text matched by a regular expression in many different ways. Your replacement text can reference as many groups as you like, and can even reference the same group more than once. ![]() If your regular expression has named or numbered capturing groups, then you can reinsert the text matched by any of those capturing groups in the replacement text.
0 Comments
Leave a Reply. |