-1

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.

  • Please remove the screen shots and return the question to being _text_. Pictures of text do no one any good. – matt Nov 23 '19 at 18:46
  • In your particular case there is no need for `\1` or `\3` because you know they are `"`. So the problem doesn't really arise. – matt Nov 23 '19 at 18:48

1 Answers1

2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Foregoing the \1 and \3 and simply typing in the quotes works. However, this is not an accepted solution if for example this operation needs to be done on hundreds of XML files. In such case I would need to go about it using backrefs. Thanks though! – Projectguru Nov 23 '19 at 19:38
  • Also, found a typo on the title of this question. Is there a way to correct that? Or better yet I would call it as you suggested "how to write a replacement group number followed by a number". – Projectguru Nov 23 '19 at 19:40