find and remove pattern

A place to try and solve your RegEx problems.
Post Reply
vx53
Posts: 3
Joined: Sun Jan 18, 2015 2:34 pm

find and remove pattern

Post by vx53 »

Hello!
I am experiencing some difficulties.
Could You help me?
Is it possible to find a string of the form (html file):

<tr class="OutOfBlock"><td /><td>DD.MM.YYYY</td><td>HH:MM:SS</td><td>+HH:00</td><td>some text with ()_:,. etc.</td><td>some text with ()_:,. etc.</td><td></td><td>some text with ()_:,. etc.</td><td></td><td>some text with ()_:,. etc.</td><td>0,0000</td><td /></tr>

and remove it if in the end found "0,0000"?
*the date and time, timezone variable.
In advance i thank you for the assistance provided.
Best regards.
User avatar
DigitalVolcano
Site Admin
Posts: 1717
Joined: Thu Jun 09, 2011 10:04 am

Re: find and remove pattern

Post by DigitalVolcano »

This should find the block-

Code: Select all

<tr class="OutOfBlock"><td /><td>DD\.MM\.YYYY</td><td>HH:MM:SS</td><td>\+HH:00</td><td>.*?</td><td>.*?</td><td></td><td>.*?</td><td></td><td>.*?</td><td>0,0000</td><td /></tr>
note the escaped characters and the wildcards.

You can replace with nothing to remove the strings. Always backup first!
vx53
Posts: 3
Joined: Sun Jan 18, 2015 2:34 pm

Re: find and remove pattern

Post by vx53 »

Hmmm, ... I have a html file containing some similar lines, here are some (internal code) of them:
<tr class="OutOfBlock"><td /><td>01.11.2014</td><td>17:15:43</td><td>+03:00</td><td>smsvsr_723</td><td>Location: asdfgh</td><td></td><td>sms o</td><td></td><td>1</td><td>3,3474</td><td /></tr>
<tr class="OutOfBlock"><td /><td>01.11.2014</td><td>17:16:05</td><td>+03:00</td><td></td><td>Location: zxcvbn</td><td></td><td>ussd</td><td>U</td><td>1</td><td>0,0000</td><td /></tr>
<tr class="OutOfBlock"><td /><td>27.11.2014</td><td>10:32:26</td><td>+03:00</td><td>smsvsr_1234</td><td>Location: qwerty</td><td></td><td>sms o</td><td></td><td>1</td><td>0,0000</td><td /></tr>
after applying the script patterns (<tr ... </tr>) containing 0,0000 must be removed.
For example, upon detection of template <tr ... 0,0000 ... </ tr> this line is removed.
* When I enter your expression, nothing happens (probably need to convert, for example, to search for <tr need to write \<tr etc.)
Is this possible?
Thank you.
User avatar
DigitalVolcano
Site Admin
Posts: 1717
Joined: Thu Jun 09, 2011 10:04 am

Re: find and remove pattern

Post by DigitalVolcano »

It's probably because the expression literally looks for HH.MM.SS, etc. I didn't realize that they were placeholders for actual values in the file.

This may work, if it's not too nonspecific:

Code: Select all

<tr class="OutOfBlock"><td /><td>.*?</td><td>.*?</td><td>.*?</td><td>.*?</td><td>.*?</td><td></td><td>.*?</td><td></td><td>.*?</td><td>0,0000</td><td /></tr>
vx53
Posts: 3
Joined: Sun Jan 18, 2015 2:34 pm

Re: find and remove pattern

Post by vx53 »

Unfortunately, beginning marker is set incorrectly:
instead remove only the second line, the script removes both

Code: Select all

<tr class="OutOfBlock"><td /><td>DD.MM.YYYY</td><td>HH:MM:SS</td><td>+HH:MM</td><td></td><td></td><td></td><td></td><td></td><td></td><td>40,0000</td><td /></tr>
<tr class="OutOfBlock"><td /><td>DD.MM.YYYY</td><td>HH:MM:SS</td><td>+HH:MM</td><td></td><td></td><td></td><td></td><td></td><td></td><td>0,0000</td><td /></tr>
Is there a solution?
Post Reply