+3
Under review

Help with Regex find/replace backreferences

Kerim Friedman 9 years ago updated by Bjarne Dein 3 years ago 3
I've seen Regex handle finding and replacing backreferences in different ways, but I can't figure out how it works in Textastic for Mac and there isn't any documentation that I can find. Below is a discussion from a Regex tutorial website. None of the methods discussed seem to work for me.

> Numbered Backreferences

> 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. Your replacement text can reference as many groups as you like, and can even reference the same group more than once. This makes it possible to rearrange the text matched by a regular expression in many different ways. As a simple example, the regex \*(\w+)\* matches a single word between asterisks, storing the word in the first (and only) capturing group. The replacement text <b>\1</b> replaces each regex match with the text stored by the capturing group between bold tags. Effectively, this search-and-replace replaces the asterisks with bold tags, leaving the word between the asterisks in place. This technique using backreferences is important to understand. Replacing *word* as a whole with <b>word</b> is far easier and far more efficient than trying to come up with a way to correctly replace the asterisks separately.

> The \1 syntax for backreferences in the replacement text is borrowed from the syntax for backreferences in the regular expression. \1 through \9 are supported by the JGsoft applications, Delphi, Perl (though deprecated),Python, Ruby, PHP, R, and Tcl. Double-digit backreferences \10 through \99 are supported by the JGsoft applications, Delphi, and Python. If there are not enough capturing groups in the regex for the double-digit backreference to be valid, then all these flavors treat \10 through \99 as a single-digit backreference followed by a literal digit. The flavors that support single-digit backreferences but not double-digit backreferences also do this.

> $1 through $99 for single-digit and double-digit backreferences are supported by the JGsoft applications, Delphi,.NET, Java, JavaScript, VBScript, PCRE2, PHP, and XPath. These are also the variables that hold text matched by capturing groups in Perl. If there are not enough capturing groups in the regex for a double-digit backreference to be valid, then $10 through $99 are treated as a single-digit backreference followed by a literal digit by all these flavors except .NET, Perl, and PCRE2.

>Putting curly braces around the digit ${1} isolates the digit from any literal digits that follow. This works in the JGsoft applications, Delphi, .NET, Perl, PCRE2, PHP, and XRegExp.

http://www.regular-expressions.info/replacebackref.html
Under review
Textastic for Mac does not currently have regular expression search and replace. Only the iOS version supports it at the moment.
+1

regex is really a must for me!

+2

Hi Alexander,

When will RegEx be enabled in the Mac version?

As @Allen states above, it's HIGHLY needed, and why on iPad and not on the Mac?

Venlig hilsen/Best Regards,


Bjarne Dein