haw to remove all lines contains specified caracters ?

Questions about XML that are not covered by the other forums should go here.
cojocarua
Posts: 2

haw to remove all lines contains specified caracters ?

Sat Apr 19, 2014 9:17 am

Heloo
I need help with editing xml file with many producs ( >1000)
I want to remove all lines with contain specified caracters, for example my code is:

<media><images>http://www.chinabuye.com/media/catalog/product/f/i/file_2209_146.jpg</images><images>http://www.chinabuye.com/media/catalog/product/7/4/74039.jpg</images><images>http://www.chinabuye.com/media/catalog/product/f/i/file_2202_240.jpg</images><images>http://www.chinabuye.com/media/catalog/product/f/i/file_2208_178.jpg</images></media>


I need to remove all lines contains "<images>http://www.chinabuye.com/media/catalog/product/f/i/"

or all lines with images like that: <images>http://www.chinabuye.com/media/catalog/product/f/i/file_2209_146.jpg</images>

I need to keep only this type of images : <images>http://www.chinabuye.com/media/catalog/product/7/4/74039.jpg</images> what contains a number after: <images>http://www.chinabuye.com/media/catalog/product/

:?: what method exists for this ?
thanks
adrian
Posts: 2337

Re: haw to remove all lines contains specified caracters ?

Tue Apr 22, 2014 11:37 am

Hi,

Removing entire lines is a bit extreme, you could accidentally remove useful code found on the same line. Are you sure it's the entire lines you want to remove and not just the respective elements?

You can use the Find/Replace dialog (or Find/Replace in Files for multiple files) from Oxygen with a regular expression like the following.

- For removing entire lines (not recommended):

Code: Select all

^.*?<images>\Qhttp://www.chinabuye.com/media/catalog/product/f/i/\E.*?$

If you want to also match/remove the line breaks (the empty lines), add a \n at the end of the expression (after the $).

- For removing only the specific images elements (recommended):

Code: Select all

<images>\Qhttp://www.chinabuye.com/media/catalog/product/f/i/\E.*?</images>

To explain the expression:
- ^ is the line start
- .*? is a sequence of any number of characters (non-greedy)
- \Q and \E - start/end literal quote (characters between \Q and the next \E are taken literally and are not interpreted as regular expressions)
- $ is the line end.

Make sure the Regular expression option is enabled and use the Find/Replace and/or the Find All/Replace All buttons.

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

Re: haw to remove all lines contains specified caracters ?

Tue Apr 22, 2014 2:32 pm

thank you verry much :D :D :D

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 0 guests