Sublime Forum

Using RegReplace in Sublime Text 3

#1

Install the RegReplace plugins in Sublime Text 3 to make several changes in a document. Following the documentation create the rules of search and substitution, but I present several problems to which I can not find the solution. These are the rules created.

 {
     "format": "3.0",
     "replacements":
     {

         "cambio_afiliacion":
         {
             "find": "\\affil{([0-9,]*)}",
             "replace": "<sup>\\1</sup>",
             "greedy": true,
             "greedy_scope": true
         },

         "cambio_section":
         {
             "find": "\\section{(.+?)}",
             "replace": "<h3>\\1</h3>",
             "greedy": true,
             "greedy_scope": true
         },
         "cambio_href":
         {
             "find": "\\href{(.+?)}{(.+?)}",
             "replace": "<a href=\"\\1\">\\2</a>",
             "greedy": true,
             "greedy_scope": true
         },
     }
 }

And this is the shortcut you create to run it in Default.sublime-keymap

 {   
         "keys": ["ctrl+alt+j"],
         "command": "reg_replace",
         "args": {
             "replacements": [
                                 "cambio_afiliacion",
                                 "cambio_href",
                                 "cambio_section",
         ],
             "find_only":false,
         }
     },

The text of the document to be edited is as follows

\href{google.com}{google.com}
Ivonne Narváez Zurita\affil{1}*
\section{Introducción}

When you execute the shortcut you only make the changes in this way

\<a href="google.com">google.com</a>
Ivonne Narváez Zurita\affil{1}*
\section{Introducción}

and should get this result

<a href="google.com">google.com</a>
Ivonne Narváez Zurita<sup>1</sup>*
<h3>Introducción</h3>

I can not find where the error can be that does not execute all the replacements and does not perform them in the correct way as shown in the\href where I get \<a>.

0 Likes

#2

This has been answered over on StackOverflow where it was also asked: https://stackoverflow.com/questions/54537897/using-regreplace-in-sublime-text-3.

1 Like