2

This is the original HTML:

<td class="danish">newtext</td>
<td><?php audioButton("../../audio/lessons/01/oldtext","oldtext"); ?></td>
<td><?php audioButton("../../audio/lessons/01/slow/oldtext_slx","oldtext_slx","1"); ?></td>

I want to replace 'oldtext' with 'newtext' using the RegReplace package in Sublime Text 2.

This is what I have in reg_replace.sublime-settings (no need to analyze the whole thing. The point is that it has a few (.*) in it):

{
"replacements": {
    "audiobutton_rep": {
                "find": "<td class=\"danish\">(.*)</td>\\n.*<td><\\?php audioButton\\(\"(.*)/.*\",\".*\"\\); \\?></td>\\n.*<td><\\?php audioButton\\(\"(.*)/.*\",\".*\",\"1\"\\);.*\\?></td>",
                "replace": "<td class=\"danish\">$1</td>\n<td><?php audioButton(\"$2/$1\",\"$1\");?></td>\n<td><?php audioButton(\"$3/$1_slx\",\"$1_slx\",\"1\");?></td>",
                "greedy": true,
                "case": false
    },

This is the command in default.sublime-commands:

{
    "caption": "Reg Replace: XXXXXXXXXXXXXXXX",
    "command": "reg_replace",
    "args": {"replacements": ["audiobutton_rep"] }
 },

The capture groups don't work, so the output looks like this:

<td class="danish">$1</td>
<td><?php audioButton("$2/$1","$1");?></td>
<td><?php audioButton("$3/$1_slx","$1_slx","1");?></td>

It works perfectly when I run it on its own, but not here.

Moogal
  • 107
  • 1
  • 9
  • 1
    Maybe not very helpful in this case, but still useful to keep in mind: http://stackoverflow.com/a/1732454/2224996 – maja Sep 03 '16 at 19:15
  • Well OK then :) But it works most of the time. Maybe my luck's finally run out. – Moogal Sep 03 '16 at 21:49

1 Answers1

3

You should be using \\1, \\2 and \\3 instead of $1, $2 and $3.

Sublime Text's built-in search/replace uses the Boost library, which accepts either $1 or \1 in the replacement string, and most other flavors accept only $1. But RegReplace is written in Python, which uses backslashes only.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156