Problem with Regular Expression Search
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 20
- Joined: Mon Aug 04, 2014 5:18 pm
Problem with Regular Expression Search
I'm having some trouble using the Regular Expression search feature in Find/Replace. When I type \ in the Find box, it pops up with a hint saying "The expression "\{\n\}" matches the text "{n}"." To test this, I entered "{n}" into my file and hit Find but I'm getting String not found as a result. I have Regular expression checked, so I'm not sure what the problem is.
What I'm trying to do is search for this:
xtrc="/w:document/w:body[1]/w:p[299]"
where the digits in the brackets are wildcards. I did some trials and could not get it to work and then after it couldn't find the "{n}", I became worried that my Regex search isn't working. Any advice?
Thanks!
Peyton
What I'm trying to do is search for this:
xtrc="/w:document/w:body[1]/w:p[299]"
where the digits in the brackets are wildcards. I did some trials and could not get it to work and then after it couldn't find the "{n}", I became worried that my Regex search isn't working. Any advice?
Thanks!
Peyton
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Problem with Regular Expression Search
Hi,
Note that \ is a special character in regular expressions. So, if you have the option Regular expression enabled when you type \ in the Find box, a list pops up with all the expressions that start with '\'. You seem to have misinterpreted the example given for \. Searching for {n} won't yield any results, since it's a broken regular expression.
where:
- \[ is the escape sequence for the special character [
- \d+ matches one or more digits
Regards,
Adrian
Note that \ is a special character in regular expressions. So, if you have the option Regular expression enabled when you type \ in the Find box, a list pops up with all the expressions that start with '\'. You seem to have misinterpreted the example given for \. Searching for {n} won't yield any results, since it's a broken regular expression.
Search for:What I'm trying to do is search for this:
xtrc="/w:document/w:body[1]/w:p[299]"
where the digits in the brackets are wildcards. I did some trials and could not get it to work and then after it couldn't find the "{n}", I became worried that my Regex search isn't working. Any advice?
Code: Select all
xtrc="/w:document/w:body\[\d+\]/w:p\[\d+\]"
- \[ is the escape sequence for the special character [
- \d+ matches one or more digits
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 20
- Joined: Mon Aug 04, 2014 5:18 pm
Re: Problem with Regular Expression Search
Adrian, you were so helpful for my last question I hope you can help me out again!
I'm using the Word2DITA conversion tool and there are quite a few find/replaces that I need to do to get the DITA files as I want them. I'm nearly there, but the questions are giving me a bit of grief.
I want to find the correct answer and add the lcCorrectReponse2 element after my closing lcAnswerContent2.
Here's an example of what I need to search:
And this is what I'd like to replace it with:
I'm able to use the regex search to find , but when I replace it with the same expression plus lcCorrectResponse2, I get gibberish as my answer text.
This is my find:
And this is the replace I have that's not working (I have that \s* in there just in case there is an extra space after the text):
When I do this find/replace, I actually get w*s* in the place of False.
Any suggestions?
Thanks!!
Peyton
I'm using the Word2DITA conversion tool and there are quite a few find/replaces that I need to do to get the DITA files as I want them. I'm nearly there, but the questions are giving me a bit of grief.
I want to find the correct answer and add the lcCorrectReponse2 element after my closing lcAnswerContent2.
Here's an example of what I need to search:
Code: Select all
<lcAnswerOptionGroup2>
<lcAnswerOption2>
<lcAnswerContent2><pointValue value="1"/>False</lcAnswerContent2>
</lcAnswerOption2>
<lcAnswerOption2>
<lcAnswerContent2>True</lcAnswerContent2>
</lcAnswerOption2>
</lcAnswerOptionGroup2>
And this is what I'd like to replace it with:
Code: Select all
<lcAnswerOptionGroup2>
<lcAnswerOption2>
<lcAnswerContent2><pointValue value="1"/>False</lcAnswerContent2><lcCorrectResponse2/>
</lcAnswerOption2>
<lcAnswerOption2>
<lcAnswerContent2>True</lcAnswerContent2>
</lcAnswerOption2>
</lcAnswerOptionGroup2>
Code: Select all
<lcAnswerContent2><pointValue value="1"/>False</lcAnswerContent2>
This is my find:
Code: Select all
<pointValue value="1"/>\w*\s*</lcAnswerContent2>
Code: Select all
<pointValue value="1"/>\w*\s*</lcAnswerContent2><lcCorrectResponse2/>
Any suggestions?
Thanks!!
Peyton
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Re: Problem with Regular Expression Search
You need to use capture groups with parentheses.
Find:
(note the brackets around the element content)
Repalce:
(note the "$1" to refer to the content in the brackets from the regexp.)
Patrik
Find:
Code: Select all
<pointValue value="1"/>(\w*\s*)</lcAnswerContent2>
Repalce:
Code: Select all
<pointValue value="1"/>$1</lcAnswerContent2><lcCorrectResponse2/>
Patrik
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Problem with Regular Expression Search
Hi,
I would like to mention that since you just want to add something after the search match, without changing it, you can simply use $0 (the entire match) in the replace string to keep the original match unmodified.
Replace with:
I would like to mention that since you just want to add something after the search match, without changing it, you can simply use $0 (the entire match) in the replace string to keep the original match unmodified.
Replace with:
Code: Select all
$0<lcCorrectResponse2/>
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
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