Sign in to follow this  
Followers 0
Who

Problem with StringRegExp

9 posts in this topic

I'm really suck into StringRegExp trouble. I have this PHP code :

<?php
$subject = "abcdef";
$pattern = '/^def/';
preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
?>

Which will produce :

Array
(
    [0] => Array
        (
            [0] => def
            [1] => 0
        )

)

And I get it into AutoIT :

#include <Array.au3>
$array = StringRegExp('abcdef', '/^def/')
_ArrayDisplay($array)

But nothing happens. Please I'm need your help.

Share this post


Link to post
Share on other sites



Set a flag in StringRegExp...

#include <Array.au3>
$array = StringRegExp('abcdef', '/^def/',2)
_ArrayDisplay($array)

www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Share this post


Link to post
Share on other sites

Set a flag in StringRegExp...

#include <Array.au3>
$array = StringRegExp('abcdef', '/^def/',2)
_ArrayDisplay($array)
$array = StringRegExp('abcdef', '/^def/',2)
for $i = 0 to UBound($array) - 1
    msgbox(0, "Matches - " & $i, $array[$i])
Next

I have tried as you told me but it doesn't work at all. The program shows nothing then :). Can you give me another suggestion please ?

Share this post


Link to post
Share on other sites

I suggest looking at the StringRegExp() function in the help file. It has a good description on how to use it.


www.itoady.com

A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding

Share this post


Link to post
Share on other sites

When set the flag to 2, then the error is 1, which mean no matches in the array. I have tried a different test but it can't be helped. Can you explain more please ?

Share this post


Link to post
Share on other sites

When set the flag to 2, then the error is 1, which mean no matches in the array. I have tried a different test but it can't be helped. Can you explain more please ?

AutoIt RegExp matching is not the same syntax as PHP. Could you explain in a few sentences what the PHP matching is trying to do? Or what you are trying to do? ... so that we get some background and can suggest how to do it in AutoIt ...

Share this post


Link to post
Share on other sites

AutoIt RegExp matching is not the same syntax as PHP. Could you explain in a few sentences what the PHP matching is trying to do? Or what you are trying to do? ... so that we get some background and can suggest how to do it in AutoIt ...

After many tries I realized that the AutoIT Regexp doesn't have ending delimiter (/) like in PHP :P . After removing the two (/) and (/i) in my pattern, the results are right but I don't know whether this action can affect or not :)

Share this post


Link to post
Share on other sites

After many tries I realized that the AutoIT Regexp doesn't have ending delimiter (/) like in PHP :P . After removing the two (/) and (/i) in my pattern, the results are right but I don't know whether this action can affect or not :)

I'm not sure I understand "whether this action can affect or not"? Are you trying to recrate a PHP script in AutoIt? Surely the test would be that the AutoIt script does what the PHP used to do ... or have I missed something?

Share this post


Link to post
Share on other sites

I mean after I deleted the PHP ending delimiters in AutoIT program, the results of AutoIt are equal to PHP :)

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