Regex not working?

Oxygen general issues.
luxlunae
Posts: 26
Joined: Wed Jun 17, 2015 10:01 pm

Regex not working?

Post by luxlunae »

regexr.com says that :

<name type="personal">\n[ \t]+<displayForm>Trust</displayForm>

should accurately match

Code: Select all

					   <name type="personal">
<displayForm>Trust</displayForm>

(I'm doing a find replace "personal" with "corporate" where displayForm="trust") but it doesn't work. Any ideas why oxygen's regex is different from the web engine I'm testing on?

It is also possible this could easily be done with xquery, I can identify the attributes but I don't know how to change the value.

//mods:displayForm[text()[contains(.,'Trust')]]/ancestor::mods:name/@type correctly identifies the "personal" attributes I need to change.
luxlunae
Posts: 26
Joined: Wed Jun 17, 2015 10:01 pm

Re: Regex not working?

Post by luxlunae »

The forum has stripped out the indentation of my two xml lines but they are indented and different amounts.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Regex not working?

Post by adrian »

Hi,

Oxygen uses in its Find/Replace tools Java regex which is based on Perl 5 regex.

AFAIK \t is the TAB character, so unless your code is indented strictly with TABs, it won't work.
Why not use \s (generic whitespace) instead of \t?

Regards,
Adrian

PS: Use the "Code" tag from the message post toolbar to preserve spaces.
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
luxlunae
Posts: 26
Joined: Wed Jun 17, 2015 10:01 pm

Re: Regex not working?

Post by luxlunae »

changing \t to \s does not work either.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Regex not working?

Post by adrian »

Hi,

Are you using the Find/Replace dialog with an open editor, or the Find/Replace in Files dialog on files from the file system?
Please check your Find options for filters (XPath or XML search options).

I tested and even the initial regexp with \t is working for me (there's a space before \t that I did not notice before) in the Find/Replace dialog with Options: Regular expression enabled. All these work for me there:

Code: Select all

<name type="personal">\n[ \t]+<displayForm>Trust</displayForm>

Code: Select all

<name type="personal">\n\s+<displayForm>Trust</displayForm>

Code: Select all

<name type="personal">\s+<displayForm>Trust</displayForm>
I recommend the last one for simplicity.

If you're searching with the Find/Replace in Files dialog avoid using \n as the line terminator in your regexp. In my case, since I'm in Windows the line terminator is \r\n, so it won't work with just \n. It's best to just use \s to avoid platform specific line terminators.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply