Find and replace using wildcard character in Notepad++

31,422

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

enter image description here

Share:
31,422

Related videos on Youtube

Evanss
Author by

Evanss

Updated on September 18, 2022

Comments

  • Evanss
    Evanss over 1 year

    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>
    
    • sean christe
      sean christe over 11 years
      Hope it isn't XML or HTML since that would break it.
    • MetaGuru
      MetaGuru over 11 years
      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?
    • amiregelz
      amiregelz over 11 years
      @ioSamurai I thought it might have been a mistake too; it doesn't make much sense.
    • xiamx
      xiamx over 11 years
      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/…
  • sean christe
    sean christe over 11 years
    If the option numbe goes to multiple digits, change (\d) to (\d+)
  • amiregelz
    amiregelz over 11 years
    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">.
  • sean christe
    sean christe over 11 years
    that is true. I usually do very explicit regexes then genralize them down later.