Sublime Forum

[Solved] Adding extra slashes to replace function

#1

Hi all,

Simple issue. I’m trying to replace a string such that it dynamically replaces the individual parts by name and position. All works well, except I need an extra slash in the string results.

Original string: g70_vo_qk.ogg

Find What code: (\w+?)(\w+.\w+)
Replace code: =FMODSoundAdd("sounds\\chars\\1\\1
\2",0,0);

Current result: =FMODSoundAdd(“sounds\ars\g70\g70_vo_qk.ogg”,0,0);

Desired result: =FMODSoundAdd("sounds\\chars\\g70\\g70_vo_qk.ogg",0,0);

I can get a result with single slashes, but I need double slashes for my needs.

Any guidance would be appreciated. Thanks in advance!

0 Likes

#2

I don’t know if you’re using ST for your regex or something else, but they don’t give the results you describe. What you seem to want is the following:

find: (\w+?)_(\w+.\w+)
repl: =FMODSoundAdd("sounds\\chars\\\1\\\1_\2",0,0);

I added the underscore as a delimiter in the find expression and 3 instead of 2 backslashes in the first capture group references in the replace expression. Also the underscore is reinserted there.

You can test your regexes and get explanations here: https://regex101.com/

1 Like

#3

Thanks for the reply nutjob2!

Sorry, forgot to mention, I’m using Sublime Text Build 3211. I tried your fix but unfortunately, I still only get single slashes:

=FMODSoundAdd("sounds\chars\g70\g70_vo_qk.ogg",0,0);

Surely it must be possible to get double slashes?

EDIT: sorry, just realized that the op had the wrong desired result. Should be:

=FMODSoundAdd("sounds\\chars\\g70\\g70_vo_qk.ogg",0,0);

0 Likes

#4

Just add \\ for each slash you want, so the replacement expression becomes:

=FMODSoundAdd("sounds\\\\chars\\\\\1\\\\\1_\2",0,0);
1 Like

#5

Ah, works perfect. Didn’t realize extra slashes needed to be added that.

Thanks for the guidance!

0 Likes

#6

The backslash is used as an escape character in regular expressions (and in many other places) so you have to use a double backslash to denote a single backslash.

Looks like this forum has a bug (or a feature) that converts \\ in ordinary text to \ thus the difficulty with your original post.

1 Like