1

I have the following:

<li id="xx"></li>
<li id="xx"></li>
<li id="xx"></li>
<li id="xx"></li>

and I'd like to use a quick find & replace to replace xx with xx01, xx02, etc. using TextMate Regular Expression search & replace.

i.e.

<li id="xx01"></li>
<li id="xx02"></li>
<li id="xx03"></li>
<li id="xx04"></li>
...

I'm struggling with this, I found how to do the other way around (ignore digit and replace all with the same), but not how to increment each replacement.

Ideas?

Ro Yo Mi
  • 14,790
  • 5
  • 35
  • 43
Adam Tal
  • 921
  • 5
  • 14
  • 35
  • 1
    It is [possible with Npp](https://stackoverflow.com/questions/7602816/notepad-incrementally-replace), no idea if that is possible with TextMate. – Wiktor Stribiżew Sep 29 '17 at 18:50
  • 1
    I've answered a similar question but using Notepad++ in case you find it useful https://stackoverflow.com/questions/25428620/regular-expression-notepad-increment-numbers-in-every-line/25429806#25429806 – Federico Piazza Sep 29 '17 at 19:45
  • 1
    @FedericoPiazza, I didn't come here for this, but I'm glad I did. I use NPP and frequently need to do exactly that. TY – Ro Yo Mi Sep 29 '17 at 20:15

1 Answers1

1

This may not be possible with TextMate Search & Replace, but there are some other TextMate options:

  1. Select the text, then use Menu > Text > Filter Through Command and a perl, sed, or awk one-liner. For previous discussions of this problem in textmate and using tmcommand or macros, see:

  2. Embed a custom command in a TextMate Bundle Editor > Menu Action. For a related command plugin (a python script) developed for Sublime Text 2 instead, see:

JeremyDouglass
  • 1,361
  • 2
  • 18
  • 31