Sublime Forum

Conditional Insertions using editors "Find & Replace"

#1

Hi,

i have a huge javascript file where I’d like to refactor some things. These are getter / setter which where objects fields so far and should be replaced with function calls.

I wrote a regex for this which uses conditional insertions in the replacement string.

I tried the following manual (TextMate) http://manual.macromates.com/en/regular_expressions [Section: 20.4.3 Conditional Insertions] which stated:

A simple test showed that either I’m doing a huge mistake and I just don’t get it or ther’s something not working as I would like it to (e.g. Sublime does not allow this):

[code] Find: (AA)(BB)
Replace: (?1:$2$2:CCCC)

Source: AABB
Output: (?1:BBBB:CCCC)

Expected: BBBB[/code]

As far as I read Sublime uses boost regex for that. Might it be that it boost-extended regex must be used for that but isn’t?
I have a tamplate using conditional insertions on the file name to create C++ namespaces which work pretty well but not as good as I want. That might be because of some error I found in there but weren’t able to fix, or it’s the same issue.

I’d like to ask you guys where the problem is. Is there someone out there whou could answer that / find my mistake or at least tell me if this does not work with sublime 3?

Thanks

Silberling

EDIT:
Oh, btw. Sublime 3 3064 on Linux x64

1 Like

#2

I have also encountered the same thing. It seems that although it is possible in snippets, the find and replace dialog, which supposedly uses the same regex engine (Boost) doesn’t support conditionals, and just outputs a literal (?n:)

http://docs.sublimetext.info/en/latest/search_and_replace/search_and_replace_overview.html
http://docs.sublimetext.info/en/latest/extensibility/snippets.html?highlight=boost#substitutions
http://www.boost.org/doc/libs/1_61_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

Build 3120 on Windows.

0 Likes

#3
1 Like