Page 1 of 1

Regex not working?

Posted: Thu Jul 30, 2015 9:46 pm
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.

Re: Regex not working?

Posted: Thu Jul 30, 2015 9:47 pm
by luxlunae
The forum has stripped out the indentation of my two xml lines but they are indented and different amounts.

Re: Regex not working?

Posted: Thu Jul 30, 2015 10:18 pm
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.

Re: Regex not working?

Posted: Thu Jul 30, 2015 11:12 pm
by luxlunae
changing \t to \s does not work either.

Re: Regex not working?

Posted: Fri Jul 31, 2015 4:27 pm
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