1

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
braveterry
  • 3,724
  • 8
  • 47
  • 59

3 Answers3

3

If you put (?s) at the start of pattern it'll enable single line mode so \r\n will not be excluded from matching .*

E.g., the following matches the whole of the branch element (in UEStudio 6 with Perl style regular expression):

(?s)<branch id="attribute">.*</branch>

Doing a little experiment some other Perl options are supported too. e.g. (?sx-i) at the start would be Single line, ignore eXtra whitespace in pattern, case sensitive (it seems to default to case insensitive).

codybartfast
  • 7,323
  • 3
  • 21
  • 25
2

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eddie
  • 53,828
  • 22
  • 125
  • 145
  • I don't know if UltraEdit supports the /s modifier like the OP used, but the [\s\S] trick should work just as well. That, plus the '?' for non-greedy matching, should answer the question in full. – Alan Moore Jan 30 '09 at 04:34
  • Thanks. This works for me. The bit about the greedy matching is useful as well. – braveterry Jan 30 '09 at 14:59
-2

Have you tried:

/<branch id="attribute">[.\n]*</branch>/gis
unclerojelio
  • 435
  • 6
  • 12
  • He's asking about the regex syntax in a specific text editor, which doesn't use the syntax you are showing. Also, \n may or may not match \r\n that is used on Windows, so you need to use [.\r\n] not just [.\n] – Eddie Jan 29 '09 at 22:07