Sign in to follow this  
Followers 0
Buffo

Help With Regexp

17 posts in this topic

I need a Regex for the following scenario:

http://www.address.com/folder/xyz.htmlX

The X can be a whitespace character (\s) or a " (ASCII 34).

I am not able to put special characters in an or statement.

StringRegExp($test, "(http://www.address.com/folder/.+\.html[\s|"]

or

StringRegExp($test, "(http://www.address.com/folder/.+\.html[\s"]

doesn't work.

Can anyone help me?

Thx a lot :)

Regards,

Buffo

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe:

StringRegExp($test, '(http://www.address.com/folder/.+?html[^:alpha:]{1})',3)
Edited by Simucal

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Thx for your reply. But this won't work.

It has to be \s or " and nothing else.

Regards

Share this post


Link to post
Share on other sites

Perhaps another expressed question will help:

Is it possible and if yes - how is it possible to OR characters with special

meanings?

For example: \s OR \w OR \d

What's the regular expression for this term?

[\s|\w|\d] isn't working...

Anyone an idea?

Regards,

Buffo

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

StringRegExp($string, '(http://www.address.com/folder/.+?html\s{1})|(http://www.address.com/folder/.+?html"{1})|(http://www.address.com/folder/.+?html\w{1})',3)

Or something like:

StringRegExp($string, 'StringRegExp($string, '(http://www.address.com/folder/.+?html(\s{1}|"{1}|\w{1}))',3)

With this last example however, end character \s " or \w will be everyother item in the array, it didnt work as a non-capturing group. This shows nested groups.

I believe the reason [\w\s"] doesnt work is like it says in the help file:

Note that special characters do not retain their special meanings inside a set, with the exception of \b, \n, \r, \t, and \\. \^, \- and \] match the escaped character inside a set.

So \w and \s dont work. Edited by Simucal

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

As it stands currently, you can't indicate sets with an escaped character.

[\s]

This means nothing to the StringRegExp() function; in fact, you will receive an error in the pattern string. In order to do what you intend to, you must use something along the lines of this:

StringRegExp($test, '(http://www.address.com/folder/.+?html[:space:|"])')

Edit: Oops, Simucal beat me to the reason why it wouldn't work.

Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

I knew neogia would come to the rescue :)


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thx for your help :)

After a few trial and error it seems to work with completing \>

Edited by Buffo

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Another question :)

How to "OR" more than one character?

How to realize? With one character [ab] or [a|b] no problem (btw. What's the difference between?)

But with more than one character it won't work for me:

[ab|cd]

[(ab)|(cd)]

What's the correct Syntax?

Thx in advance.

Regards,

Buffo

Edited by Buffo

Share this post


Link to post
Share on other sites

#11 ·  Posted

i dont think that returns t

Share this post


Link to post
Share on other sites

#12 ·  Posted

i dont think that returns t

LOL, if you use it right it does:
$Test = StringRegExp("test", '([te]|[st])', 1)
MsgBox(0, '', $Test[0])

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#13 ·  Posted

Sorry, but this is not what I want :">

Or perhaps I don't understand really :)

Here an other precise (but stupid :( ) example that explains what I want:

String: "fat fet fit fot fut"

I only want to get "fet" and "fot":

StringRegExp($string, "(f[eo]t)", 3) or StringRegExp($string, "(f[e|o]t)", 3)

will work.

String: "faat feet fiit foot fuut"

I want to get only "feet" and "foot" as result.

StringRegExp($string, "(f[ee|oo]t)", 3)

won't work.

I need here the correct syntax (even if there are more than 2 characters that should be "OR"-ed)

Regards,

Buffo

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I doubt seriously this is right, I would just use StringInStr() for something to be word specific personally

$sRegExp = StringRegExp("fat fet fit fot fut", '(f[e]t|f[o]t)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf

Edit:

Actually the more I think about it, these are all the same:

$sRegExp = StringRegExp("fat fet fit fot fut", '(f[e]t|f[o]t)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf

$sRegExp2 = StringRegExp('faat feet fiit foot fuut', '(f[e][e]t|f[o][o]t)', 3)
If IsArray($sRegExp2) Then
    For $j = 0 To UBound($sRegExp2) - 1
        MsgBox(0, $j, $sRegExp2[$j])
    Next
EndIf

$sRegExp3 = StringRegExp("fat fet fit fot fut", '(fet|fot)', 3)
If IsArray($sRegExp3) Then
    For $k = 0 To UBound($sRegExp3) - 1
        MsgBox(0, $k, $sRegExp3[$k])
    Next
EndIf

$sRegExp4 = StringRegExp('faat feet fiit foot fuut', '(feet|foot)', 3)
If IsArray($sRegExp4) Then
    For $l = 0 To UBound($sRegExp4) - 1
        MsgBox(0, $l, $sRegExp4[$l])
    Next
EndIf

Edit2:

This looked more like what you were looking for... But of course could be wrong:

$sRegExp = StringRegExp("fat fet feet fot fut foot", '(f[e]{1,2}t|f[o]{1,2}t)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf
Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#15 ·  Posted

Ah, I see... I have to use round brackets instead of the squared.

Now there is a little understanding problem:

String: "faat feet fiit foot fuut"

Regular Expression: (f(ee|oo)t)

returns:

1. oo

2. foot

3. ee

4. feet

But I only want the whole (2+4) expression.

This can only be a simple thing. Could you help me a last time? :)

Regards,

Buffo

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Ah, I see... I have to use round brackets instead of the squared.

Now there is a little understanding problem:

String: "faat feet fiit foot fuut"

Regular Expression: (f(ee|oo)t)

returns:

1. oo

2. foot

3. ee

4. feet

But I only want the whole (2+4) expression.

This can only be a simple thing. Could you help me a last time? :)

Regards,

Buffo

I'd like to personally find a better/cleaner solution but I must admit... the time is catching up to me, you could do something like this I guess:
$sRegExp = StringRegExp("faat feet fiit foot fuut", '(f(ee|oo)t)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        If Mod($i, 2) <> 0 Then MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf

Edit:

This is cleaner:

$sRegExp = StringRegExp("faat feet fiit foot fuut", '(f[e|o]{2}t)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf
But I still don't know if it's right.

Edit2:

If your just trying to find the word that has the double letters in them, this might be fun too:

$sRegExp = StringRegExp("need faat feet fiit foot fuut loot hoot", '([a-z][e|o]{2}[a-z])', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf

Edit3:

Or even this:

$sRegExp = StringRegExp("need faat feet fiit foot fuut loot hoot sheeze", '([a-z]{1, 2}[e|o]{2}[a-z]{1, 2})', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, $sRegExp[$i])
    Next
EndIf

Edit4:

Or maybe:

$sRegExp = StringRegExp("need faat feet fiit foot fuut loot hoot Sheeze", '(\a{1,2}[e|o]{2}\a{1,2})', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, StringLen($sRegExp[$i]) & @CRLF & $sRegExp[$i])
    Next
EndIf

Edit5:

Or maybe:

$sRegExp = StringRegExp("need faat feet fiit foot fuut loot hoot Sheeze", '(\a*[e|o]{2}\a*)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, StringLen($sRegExp[$i]) & @CRLF & $sRegExp[$i])
    Next
EndIf
I liked this one the best I think.

Edit6:

Or Maybe:

$sRegExp = StringRegExp("need faat feet fiit foot fuut loot hoot Sheeze", '(\a*[e*|o*]\a*)', 3)
If IsArray($sRegExp) Then
    For $i = 0 To UBound($sRegExp) - 1
        MsgBox(0, $i, StringLen($sRegExp[$i]) & @CRLF & $sRegExp[$i])
    Next
EndIf
Ok man, I'm off to bed, good luck! Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#17 ·  Posted

...Regular Expression: (f(ee|oo)t)...

Well, actually, this is supposed to work:

Regular Exp[b][/b]ression: (f(?:ee|oo)t)

The "?:" added in there means "non-capturing group" but it seems to error out. This seems to be a bug, but I'll do more investigating.

@SmOke_N: That is hilarious how many examples you came up with. There's always at least a gazillion ways to make one regular expression.


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

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