Search code examples
regextext-editorultraedit

Is it possible to match a pattern using a regular expression across a newline in UltraEdit?


The UltraEdit text editor includes a Perl and Unix compatible regular expression engine for searching.

I want to be able to match a string line this:

<branch id="attribute">
    <leaf id="attribute"/>
    <leaf id="attribute"/>
    <leaf id="attribute"/>
</branch>

With something like this:

/<branch id="attribute">.*</branch>/gis

Is there a way to accomplish this using UltraEdit?


Solution

  • If you have Perl regular expressions selected, you can do something like:

    <branch id="attribute">[\s\S]*</branch>
    

    where \s is any whitespace character, including newline and return and \S is any other character. Note that this is greedy by default, so if you have the following string:

    <branch id="attribute">
      <leaf id="attribute"/>
      <leaf id="attribute"/>
      <leaf id="attribute"/>
    </branch>
    <branch id="attribute">
      <leaf id="attribute"/>
      <leaf id="attribute"/>
      <leaf id="attribute"/>
    </branch>
    

    then the one regular expression will find the ENTIRE string as one match. If you don't want to do this, then add ? as follows:

    <branch id="attribute">[\s\S]*?</branch>
    

    As you can see from the answers, there are many ways to accomplish this in UltraEdit!

    NOTE: Tested with UltraEdit 14.20.