regex - Find and replace all occurrences of a tag in Notepad++

07
2013-08
  • Xavier

    I am trying to find and replace all occurences of a tag <xyz..ewwef> in a text using Python or Notepad++.

    Since I got a lot of data, Python keeps hanging up when I use the regex function, so I'd prefer using Notepad++.

    But the < and > seem to mess up the search syntax, so if I try finding all <> plus their content in between using (?=<).*(?=>), Notepad is not able to find any matches.

  • Answers
  • invert

    Try using [?=<].*[?=>] in notepad++. <.*> also works.

    For processing regex on large files in Python, see this answer, and see here, and this answer too.


  • Related Question

    regex - Notepad++: Find & replace with regular expressions
  • Loris

    I have a file full of lines like this:

    <td>123.456</td>
    

    that I want to convert to:

    <td class="num">123.456</td>
    

    I tried using the advanced find/replace (with regular expressions enabled):

    find: <td>([0-9\.]+)</td>
    replace: <td class="num">\1</td>
    

    I can find my td elements fine, but somehow replace gets me an empty TD:

    <td class="num"></td>
    

    What am I doing wrong?


  • Related Answers
  • Aeo

    I've not used Notepad++ myself all that much, but you might check to make sure \1 is the correct... syntax? to use. For example, Dreamweaver uses %1 instead.

  • Loris

    It looks like it's a bug with Notepad++ or one if its plugins.

    Switching the language from HTML to normal text fixed this for me.

  • Ian

    This doesn't look like a bug to me. I know this post is a few months old, but humor me.

    In your find line: find: ([0-9.]+)

    It looks like you only told the engine to find one numeral before the period repeated one or more times. Shouldn't your regex look more like this.

    find: ([0-9]+.[0-9]+)

    Correct me if I'm wrong.