Page 1 of 1
Is there a way to replace everything but keep data that was found by wild card
Posted: Fri Oct 29, 2021 11:43 pm
by frogman7
find this set of data
</NEW>
</Id>
<Bubble>
<Ctr>.*?</Ctr>
</Bubble>
</OCtPt>
Replace this but where the wildcard data is I need it to keep the data that is in the document.
</NEW>
</LLG>
</Id>
<Bubble>
<Ctr>.*?</Ctr>
</Bubble>
</OCtPt>
Is there any way to do this?
Re: Is there a way to replace everything but keep data that was found by wild card
Posted: Mon Nov 01, 2021 12:08 pm
by whyme
Yes, use parentheses in the find field and back references in the replace field.
Where you have .*? use (.*?) in your first block of code and \1 in your second. (Note that if you're doing this in XPath, you need to use $1, but not in Oxygen's search/replace dialogue.)
Background reading:
https://www.oxygenxml.com/doc/versions/ ... ialog.html
https://www.regular-expressions.info/
Re: Is there a way to replace everything but keep data that was found by wild card
Posted: Fri Nov 19, 2021 2:22 am
by frogman7
I need to explain it better.
In my document I found 21 data rows. Meaning I have hundreds of xml tag (data rows)
<start>multiple tags and data my regex search found the 21 I wanted</start>
I either want to extract the 21 data rows or delete all the other hundreds of data rows.
for this one since there was only 21 I just manually copied and pasted them in a new xml but in future there may be hundreds so I would like to have something that would make the process more automated.
Re: Is there a way to replace everything but keep data that was found by wild card
Posted: Fri Nov 19, 2021 4:51 pm
by adrian
Hi,
I either want to extract the 21 data rows or delete all the other hundreds of data rows.
Find/Replace isn't meant to be used to extract data, it's just a text search/replace tool. You could flip the logic in the regex and use it to delete the rows that you don't need, but that's about it.
If we are talking about XML, you could write an XPath expression that matches the rows that you want and use the XPath/XQuery Builder (XQuery part) to extract the data in a new document.
See my post from this topic on how the XPath/XQuery Builder can be used to extract data:
post64012.html#p64012
Regards,
Adrian