Search code examples
regexsublimetext

Unable to selectively apply replacement text of regular expression using Sublime Text


Context

I have a very lengthy text file that I'm trying to polish using Sublime's regex find/replace option. I'm using Sublime Text's build 4113. I've reduced the essence of the text file down to this reproducible example to illustrate my question:

the          quick           
brown        fox             
jumps        over            
the          lazy_dog        

I want to replace the whitespace between the two columns of text. Sublime correctly highlights the matches with this lookbehind: (?<=[a-z]) * Please note the trailing space after the * quantifier.

Expected Behavior

Sublime's "Replace All" feature works as expected when using the above lookbehind. Replacing all instances of the regular expression with a single space produces this expected result:

the quick 
brown fox 
jumps over 
the lazy_dog 

If I attempt to iterate over the matches using a combination of "Find" and "Replace", I expect the regex cursor position to advance to each instance and permit me to selectively apply the replacement.

Unexpected Behavior

However, when I attempt to selectively apply the replacement with "Find" and "Replace", Sublime only replaces the first instance even while continuing to highlight every subsequent instance in yellow, indicating that the regex engine "sees" the match.

Can someone please help me fill the gap in my understanding? Apologies if this question has been answered already. I spent some hours searching but perhaps I'm not using the appropriate keywords.


Solution

  • The good news is you're not crazy, the bad news is this is a bug in ST. More good news is that it was fixed in build 4114 - I have verified it myself with your example on build 4115 in Linux.

    For more information, see this bug on the issue tracker: https://github.com/sublimehq/sublime_text/issues/2038