Sign in to follow this  
Followers 0
oMBRa

StringRegExp

4 posts in this topic

I found this example in the autoit help

;Option 1, using offset
$nOffset = 1
While 1
    $array = StringRegExp('<test>a</test> <test>b</test> <test>c</Test>', '<(?i)test>(.*?)</(?i)test>', 1, $nOffset)
    
    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
    Next
WEnd

but I didnt get what means (.*?)... any1 help?

Share this post


Link to post
Share on other sites

. - Match any single character (except newline).

* - Repeat the previous character, set or group 0 or more times. Equivalent to {0,}

? - The previous character, set or group may or may not appear. Equivalent to {0, 1}

Share this post


Link to post
Share on other sites

I found this example in the autoit help

;Option 1, using offset
$nOffset = 1
While 1
    $array = StringRegExp('<test>a</test> <test>b</test> <test>c</Test>', '<(?i)test>(.*?)</(?i)test>', 1, $nOffset)
    
    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
    Next
WEnd

but I didnt get what means (.*?)... any1 help?

StringRegExp('<test>a</test> <test>b</test> <test>c</Test>', '<(?i)test>(.*?)</(?i)test>', 1, $nOffset)

The pattern looks for what ever is between <test> and </test>

(.*?) basically means it's going to stop at the next character in the sequence. Remove the '?' and all of the sudden your result is:

a</test> <test>b</test> <test>c

So it's going to grab ANY character '.'

It's going to repeat it '*' UNTIL '<'

Help clarify it for you?

Share this post


Link to post
Share on other sites

yes thx

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