Sublime Forum

Automate multiple search-replace and other search-processings on paste

#1

Hi ! I’m currently working on writing a grammar taken from a language specifications to a format supported by the parser I’m using. In this frame, I often (I have a ~1000 lines file typically) have the same highly repetitive tasks to perform:

  1. Copy a snippet from the manual
  2. Paste it into my grammar file
  3. Replace all the lines starting with "([a-zA-Z-]+) = " with "\1: ", so start-statement = expression becomes start-statement: expression
  4. Replace all the quoted strings with their upper case content: "Function" becomes FUNCTION
  5. Replace all the dash-separated identifiers with underscore-separated identifiers: start-statement becomes start_statement
  6. And so on, with similar find/replace commands

I’ve thought of using macros, however you can’t use find/replace with them. I can simply use multicursor edition and regexp find/replace by hand, but it is highly repetitive and inefficient.

Can Sublime Text help in improving this kind of tasks ?

0 Likes

#2

The RegReplace package may help you for something like this.

1 Like

#3

Thanks ! It works well for replacement, do you know if I can use it for item n°4 ? Ie. do you know if I can use it to replace matched strings with their uppercase version ?

0 Likes

#4

For uppercase replace you can do a \U\1\E as your replacement string

1 Like