Search code examples
regexbbedit

BBEdit regex replace only works when using "Replace All"


Looking to replace all examples like this:

"1%"

"10%"

with:

"1.0%"

"10.0%"

Here is my regex:

"(\d+)%"

And here is my replace pattern:

"\1\.0%"

If I click "Replace" I get this error:

The replacement string couldn’t be computed, because the previous Grep search did not succeed (application error code: 12003). The replacement string couldn’t be computed, because the previous Grep search did not succeed (application error code: 12003).

However, if I click "Replace All," it works.

I'm guessing this is my error, as this is a very basic task. What am I doing wrong?


Solution

  • I realize this is an older thread, but I just encountered this problem and I believe I understand what is happening. When you use the Grep search functionality in BBEdit, it automatically finds as many matches as it can (i.e find all). The confusion for me was caused because there was only a single match, but BBEdit is still in "Find All" mode. In this case "Replace All" works, but "Replace" does not. You need to tell BBEdit which instance you want to "Replace" by clicking "Previous", or "First", even though there is only one match, and then click "Replace" or just click "Replace All". It's a bit counter intuitive, but I think that is what is happening.