Search/Replace with Regular Expressions, w/ white space

<oXygen/> general issues.
alosha
Posts: 2
Joined: Mon Feb 19, 2007 7:42 am
Contact:

Search/Replace with Regular Expressions, w/ white space

Post by alosha » Mon Feb 19, 2007 7:57 am

I am formatting large XML documents and I'd like to know more about the use of Regular Expressions in the Search/Replace dialog. There doesn't seem to be any extensive amount of information in the help file. I've been able to use regular expressions pretty successfully as long as I am not searching for multiple lines. I understand the use of the character sets and the variable set () and replacements $1, $2, etc., but I can't seem to get it to find newline characters. I tried searching for things like "\r\n" and {$NEWLINE} but those didn't work.

Some other searches also don't make sense. When I search for $^ (which I thought was end-of-line and then beginning-of-line), it should find every newline, but instead it only finds newlines at the beginning of empty lines.

I'd like two be able to do two different things:
1) Find and replace all white space in between tags "<tag1>stuff</tag1> block of white space maybe with newlines <tag2>stuff</tag2>", including newlines, spaces, tabs, etc.
2) OR Find and DELETE empty lines.

Can anybody show me how to do these things? I'm not really an expert on searching with regular expressions, so if I'm missing something obvious please point it out.

Thanks a lot,
Sarah

sorin_ristache
Posts: 4144
Joined: Fri Mar 28, 2003 2:12 pm

Re: Search/Replace with Regular Expressions, w/ white space

Post by sorin_ristache » Mon Feb 19, 2007 11:58 am

Hello,
alosha wrote:There doesn't seem to be any extensive amount of information in the help file. I've been able to use regular expressions pretty successfully as long as I am not searching for multiple lines. I understand the use of the character sets and the variable set () and replacements $1, $2, etc., but I can't seem to get it to find newline characters. I tried searching for things like "\r\n" and {$NEWLINE} but those didn't work.
The section about finding and replacing text of the User Manual explains that "the find works at line level, which means a find match cannot cover characters on more than one line." The {$NEWLINE} expression can be used only in the Replace with field of the Find/Replace dialog.
alosha wrote:Some other searches also don't make sense. When I search for $^ (which I thought was end-of-line and then beginning-of-line), it should find every newline, but instead it only finds newlines at the beginning of empty lines.
$ is the symbol for the beginning of line and ^ is the symbol for the end of line so the regexp $^ matches empty lines.
alosha wrote:1) Find and replace all white space in between tags "<tag1>stuff</tag1> block of white space maybe with newlines <tag2>stuff</tag2>", including newlines, spaces, tabs, etc.
2) OR Find and DELETE empty lines.
Find/replace works at line level in oXygen so you cannot delete any line with a find/replace operation. There is an enhancement request to extend the find/replace support to work on more than one line and probably it will be implemented in a future version.

To find and replace all white space in between tags on the same line use the expression </(.+?)>\s*<(.+?)> in the Text to find field of the Find/Replace dialog and the expression </$1><$2> in the Replace with field. The Regular expression option must be enabled.


Regards,
Sorin

alosha
Posts: 2
Joined: Mon Feb 19, 2007 7:42 am
Contact:

Post by alosha » Mon Feb 19, 2007 12:42 pm

Thanks very much.

Post Reply