Is there a way to replace everything but keep data that was found by wild card

Having trouble installing Oxygen? Got a bug to report? Post it all here.
frogman7
Posts: 3
Joined: Fri Oct 29, 2021 11:31 pm

Is there a way to replace everything but keep data that was found by wild card

Post 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?
whyme
Posts: 89
Joined: Fri Mar 08, 2013 8:58 am

Re: Is there a way to replace everything but keep data that was found by wild card

Post 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/
frogman7
Posts: 3
Joined: Fri Oct 29, 2021 11:31 pm

Re: Is there a way to replace everything but keep data that was found by wild card

Post 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.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Is there a way to replace everything but keep data that was found by wild card

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply