Sign in to follow this  
Followers 0
kseven

Need some Help with StrRegExp

5 posts in this topic

Hello @all,

after trying to find the solution for an hour now, i'm asking the pro's for a little help. i searched the forum and find one or more ways to get similar regexp's working, ... but not my one.

i'm reading a simple textfile with the source from a website in it. so far so good.

the string i'm searching for, looks like this:

<td>12345</td>

within the two tag-elements, there can be one or more digits, no characters and it can be in the text on or more times.

$TroopCount = StringRegExp($aArrayB[$k], '(?: <td>)([:digit:]+)(?: </td>)', 3)
            
For $p = 1 To $TroopCount[0]
    MsgBox(0, "info", "$TroopCount = " & $TroopCount[$p])
Next

any help is apriciated.

greetings

da seven

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hm, Funny...

$TroopCount = StringRegExp($aArrayB[$k], '<td>[:digit:]+</td>', 3)

Seems to work. As a workaround I'd remove the Tags using StringReplace.

Not the intelligent way, of course, but a solution....

$TroopCount = StringRegExp($aArrayB[$k], '(?:<td>)[:digit:]+(?:</td>)', 3)

Should do the job, but it does not... funny.

Edited by Marc

It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

m-hm ... it's not the problem. let me tell ya, how i was trying to find the right way.

at fist the RegExp looked like this, where i get an error:

$TroopCount = StringRegExp($aArrayB[$k], '[:digit:]+', 3)

after that, i tried this:

$TroopCount = StringRegExp($aArrayB[$k], '([:digit:]+)', 3)

this version worked fine, but returned every digit out of the string, which was not as usefull as i thought :P

so, the next step was to put some characters or special characters into the pattern. before and after the digits i'm searching for, comes a ">" or "<". at that moment, the RegExp returns nothing.

at this point, i searched the forum and found a example. string was something like this ...

<album>blablabla</album><artist>blablabla</artist>

... and pattern:

(?: <album>)(.?*)(?: </album>)(?: <artist>)(.?*)(?: </artist>)

i don't know, if this RegExp is workin' ... atm i don't think so.

any other ideas?

!Edit!

:nuke: you were faster by editing your post ^^

!!another edit!!

anybody who knows the editor "ultraedit32"? in this tool you are able to search any textfile by using regexp. i opened the textfile, which i'm reading in with autoit and tried to search the string with the RegExp

<td>\d+</td>
. it works fine. i must tell ya, that the RegExp in ultraedit are almost equal to the RegExp in autoit. Edited by kseven

Share this post


Link to post
Share on other sites

Could this be one of the resons the StringRegExp documentation has been pulled in 3.2.0.1 (It is suposed to be returned when the RegExp library (or documentation) has been adjusted) ?

I expected this to return a array with two elements but it only returns one

$str = "<td>12345</td>" & @CRLF & "<td>23456</td>"
$foo = StringRegExp($str, "(?:\s*<td>\s*)(\d+?)(?:\s*</td>\s*)", 3)
if @extended Then 
    msgbox(0, "TEST", UBound($foo))
    _ArrayDisplay($foo, "TEST")
EndIf

But as usual I can have got it all wrong.

Anyhow the toppost examples have a space in the regexp pattern after ?: and that will not match anything in the data sample.

Share this post


Link to post
Share on other sites

thx for your example.

i got the solution, after trying it out :P

(?i:<td>)(\d*?)(?i:</td>)

is the pattern.

so far

da seven

Share this post


Link to post
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
Sign in to follow this  
Followers 0