Search/Replace with Regular Expressions, w/ white space
Oxygen general issues.
-
- Posts: 2
- Joined: Mon Feb 19, 2007 7:42 am
Search/Replace with Regular Expressions, w/ white space
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
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
-
- Posts: 4141
- Joined: Fri Mar 28, 2003 2:12 pm
Re: Search/Replace with Regular Expressions, w/ white space
Post by sorin_ristache »
Hello,
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
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: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.
$ 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: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.
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.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.
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
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service