I find myself needing to mass update some code quite frequently. And quite frequently those updates involve replacing text or copying and pasting text. That in itself is of course as easy as hitting the replace all button in any text editor.

Though sometimes i need to make an edit a little more complicated. For instance i may need to add a character or additional text to the end of every line in my code, or i may even need to paste a certain piece of text to the beginning of every line.

I’ve searched and i’ve searched for a text editor that is capable of accomplishing this. Fortunately i finally found such an editor.

Sublime Text 2 is a free text editor which has downloads for Windows, Mac and Linux. The cool thing about this text editor is that it supports REGEX (Regular Expressions).

I didn’t know this until recently that you can actually us REGEX to identify the ends and beginnings of lines, way cool right.

Heres some quick instructions on copying and pasting to the end or beginning of several lines of code or text, all at once:

  • You want to download and install Sublime.
  • Open Sublime with your text/code in the editor
  • On the find menu, click replace.
  • Then you want to click the button to the far left of the “Find What” text box that looks like an asterisk and a period. This will activate the regex.
  • In the find what text box, past either of the regext statements below depending on if you’re looking for the end or the beginning of lines.
  • Add the text you want to replace either with in the “Replace with” text box.
    Regex Statements:

  • Beginning of Line : ^[a-zA-z0-9!@#$”)(*&!+_-]
  • End of line: (?>\x0D\x0A?|[\x0A-\x0C\x85\x{2028}\x{2029}])

Now these exaxt regex statements may or may not work for you depending on the type of code or text your working with and the formatting. If you find that is not working for you, it would be helpful to do a little regex research here.

Hope this helps :0)