Jump to content

Remove string between numbers


 Share

Go to solution Solved by iamtheky,

Recommended Posts

Hi all,

I have a problem with a regex expression. I have a string with many numbers and i want remove all between them.

My string <tr> <td>30/09/2013</td> <td> 69 290 &euro; </td> <td> 9 980 </td> <td></td> </tr>

And I want the result is ;~ <tr> <td>30/09/2013</td> <td> 69290 </td> <td> 9980 </td> <td></td> </tr>

Stringstripws don't work because it's not spaces between numbers. I thing we want use [^d] but I have not find solution.

Thanks in advance

The string is in the file

Code_source_html.html

Edited by ATR
Link to comment
Share on other sites

$str = "<tr> <td>30/09/2013</td> <td> 69Â 290 </td> <td> 9Â 980 </td> <td></td> </tr> <tr> <td>30/09/2012</td> <td> 46Â 350 &euro; </td> <td>    1Â 280 </td> <td></td> </tr> <tr> <td>30/09/2011</td> <td> 12Â 030 </td> <td> 20Â 260 </td> <td></td> </tr> </tbody> </table>"

$res = StringRegExpReplace($str, '\h*(\d+)[^\d/]+(\d+)[^<]*', '$1$2')
msgbox(0,"", $res)

?

Edited by mikell
Link to comment
Share on other sites

  • Solution

$str = fileread("Code_source_html.html")
msgbox(0, '' , stringreplace($str , " " , ""))

in the string replace instead of space, i typed alt+0160

and with all spaces including those removed:

$str = fileread("Code_source_html.html")
msgbox(0, '' , stringstripws(stringreplace($str , " " , ""),8))
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

 

Please explain, I tried this and it works :huh:

$str = fileread("Code_source_html.html")

$res = StringRegExpReplace($str, '\h*(\d+)[^\d/]+(\d+)[^<]*', '$1$2')
msgbox(0,"", $res)

In fact your code replace all between numbers : 123 text with text 456 the result is 123456, but I don't want this result. I want only caracters not in a-zA-Z and 0-9

I don't say if you have seen in the file, but characters between numbes it's not space...

Link to comment
Share on other sites

it is a space, just a "No-Break Space" also known as U+00A0 or the alt code 0160.  Any reason my solution in post #5 is failing your criteria?

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

 I have a string with many numbers and i want remove all between them.

My string <tr> <td>30/09/2013</td> <td> 69 290 &euro; </td> <td> 9 980 </td> <td></td> </tr>

And I want the result is ;~ <tr> <td>30/09/2013</td> <td> 69290 </td> <td> 9980 </td> <td></td> </tr>

 

It's exactly what the regex does, it removes all (including xA0)

But this looks like a wrong way so can you please post a clear sample of expected result ?

Link to comment
Share on other sites

It's exactly what the regex does, it removes all (including xA0)

But this looks like a wrong way so can you please post a clear sample of expected result ?

$SomeString="<tr> <td>30/09/2013</td> <td> 69 290 &euro; </td> <td> 9 980 </td> <td></td> </tr>"; set, or get from HTM(L)
$timer=TimerInit()
$NewString=StringRegExpReplace($SomeString , "&.*;" , ""); replace from: "&", until: ";", to: ""
$ReplacedString=StringReplace($NewString , " " , ""); replace: " ", to "" (all spaces)
$Super=StringRegExpReplace($NewString , "(\d)\s(\d)" , "$1$2"); replace " " between the digit to: ""
msgbox(0, 'Timer: ' & TimerDiff($timer) & " ms" , "Some String         :" &  $SomeString & @CRLF & _
        "NewString (&*;)   : " & $NewString & @CRLF & _
        "ReplacedString ( ): " & $ReplacedString & @CRLF & _
        "WhatYouWant      : " & $Super)

Greetings (P.S. Give me +1 if it's help You) :-)

Edited by Wilenty
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...