regextextmateoniguruma

Regex issue - fine backwards and not forwards Textmate


I'm not very good with regular expressions but in Textmate, I'm trying to clear out some multi-lines in an XML file that looks like

<comments>
    <sub_node>....
....
</comments>

and I'm using this in the find/replace with regex,

<comments>(?m:.*)</comments>

There're multiple occurences of the above, but if I do a find, it finds the first and then selects everything in between including outside nodes till the last in the file.

If I do a find previous (backwards) from the last line it captures a block correctly. I'm not sure what I'm doing wrong here and if anyone might even suggest a far more efficient way of doing this.

Thanks.


Solution

  • You need to use non-greedy qualifiers. I don't know anything about Textmate, so I don't know if it supports them. If it doesn't, you can search for <comments> followed by any number of things that isn't </comments> followed by <comments>. (This would be more specific help, but your posted example is unfamiliar and must be some Textmate weirdness.)