Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2 RegEx replace n with n+1

Using RegEx search and replace with Sublime Text 2, how can I replace my pattern matches (n) with n+1? And if there is no way to do this with search and replace, is there another easy way to do it?

My RegEx pattern is ^(\d{1,4})\n, and I'd like to be able to do $1+1, which currently just outputs the match with a literal "+1".

like image 408
BenjaminRH Avatar asked Oct 17 '12 17:10

BenjaminRH


People also ask

How do you replace values in Sublime Text?

To use Find and Replace in Sublime Text 3, you can either click “Find” in the top-bar, then select “Replace” from the list, or you can press the keyboard shortcut Ctrl+H – the same way it works in, for example, Microsoft Office Word.

How do I insert a new line in Find and Replace?

Select the cells that you want to search. On the keyboard, press Ctrl + H to open the Find and Replace dialog box, with the Replace tab active. On the Replace tab, click in the Find What box. On the keyboard, press Ctrl + J to enter the line break character.

Does Sublime Text support regex?

Search functions in Sublime Text support regular expressions, a powerful tool for searching and replacing text. Regular Expressions find complex patterns in text.

How do I insert a line break in sublime?

To insert a new line below the current line in your code, hit Cmd–Return (Mac) or Ctrl–Enter(Windows). You can also insert a new line above the current line by using Cmd–Shift–Return(Mac) or Ctrl–Shift–Enter (Windows).


1 Answers

Regex is the wrong tool for that function. However, there is Sublime Text plugin just to do what you want: "Sublime Text plugin to increment/decrement all selected numbers"

like image 124
slackwing Avatar answered Sep 22 '22 17:09

slackwing