Jump to content

Problem with StringRegExp


 Share

Recommended Posts

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.

Link to comment
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 ?

Link to comment
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 ...
Link to comment
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 :)

Link to comment
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?
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...