views:

590

answers:

3

The UltraEdit text editor includes a Perl and Unix compatible regex 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

Does any one know of a way to accomplish this using UltraEdit?

+2  A: 

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).

it depends
This regular expression also works for me. Thanks!
braveterry
A: 

Have you tried:

/<branch id="attribute">[.\n]*</branch>/gis
unclerojelio
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
+2  A: 

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.

Eddie
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
Thanks. This works for me. The bit about the greedy matching is useful as well.
braveterry