I have very long list in this format:

<option value="adf">Option 1</option>
<option value="es3">Option 2</option>
<option value="34f">Option 3</option>

With Notpad++, how can I do a find and replace to change it to this format?:

<value="1">Option 1</option>
<value="1">Option 2</option>
<value="1">Option 3</option>
  • Hope it isn't XML or HTML since that would break it. – EBGreen Nov 30 '12 at 18:21
  • No, actually what i need to make is a little different but the example in my questions illustrates the concept. – Evanss Nov 30 '12 at 18:24
  • 4
    Did you really mean to make all the values = 1 or are they suppose to = the number of the option, so in this case they would be 1, 2, 3 respectively? – MetaGuru Nov 30 '12 at 19:07
  • @ioSamurai I thought it might have been a mistake too; it doesn't make much sense. – amiregelz Nov 30 '12 at 19:11
  • It's not really a good idea to use regex on xml.. Ideally, feed the xml to a parser then regenerate it to the format that you desire. see: stackoverflow.com/questions/1732348/… – xiamx Nov 30 '12 at 19:27

This replace should do it if I understand exactly what you want to accomplish:

enter image description here

  • If the option numbe goes to multiple digits, change (\d) to (\d+) – EBGreen Nov 30 '12 at 18:28
  • 2
    No need to mess with the name of the option at all (e.g Option 1) - you only need to change the opening option tag, i.e replacing <option value=".*"> with <value="1">. – amiregelz Nov 30 '12 at 19:03
  • that is true. I usually do very explicit regexes then genralize them down later. – EBGreen Nov 30 '12 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.