Search code examples
grepbbedit

BBEdit: how to write a replacement pattern when a back reference is immediately followed by a number


I'm new to GREP in BBEdit. I need to find a string inside an XML file. Such string is enclosed in quotes. I need to replace only what's inside the quotes.

The problem is that the replacement string starts with a number thus confuses BBEdit when I put together the replacement pattern. Example:

Original string in XML looks like this:

enter image description here


What I need to replace it with:
01 new file name.png


My grep search and replace patterns:

enter image description here

Using the replacement pattern above, BBEdit wrongly thinks that the first backreference is "\101" when what I really need it understand is that I mean "\01".

TIA for any help.


Solution

  • Your example is highly artificial because in fact there is no need for your \1 or \3 as you know their value: it is " and you can just type that directly to get the desired result.

    "01 new file name.png"
    

    However, just for the sake of completeness, the answer to your actual question (how to write a replacement group number followed by a number) is that you write this:

    \0101 new file name.png\3
    

    The reason that works is that there can only be 99 capture groups, so \0101 is parsed as \01 (the first capture group) followed by literal 01.