Oscar Fanelli
Oscar Fanelli

Reputation: 3657

Error with php regular expression

i have this code:

$text = "###12###hello###43###good###113###thefinalstring";
preg_match_all('/(.*?)###(\d*)###(.*?)/is', $text, $matches, PREG_SET_ORDER);

If I dump $matches, why there is not "thefinalstring" anywhere? Where is the error in the regular expression?

Thanks

Upvotes: 0

Views: 79

Answers (2)

Toto
Toto

Reputation: 91385

Have a try with:

$text = "###12###hello###43###good###113###thefinalstring";
preg_match_all('/###(\d*)###([^#]*)/is', $text, $matches, PREG_SET_ORDER);
print_r($matches);

output:

Array
(
    [0] => Array
        (
            [0] => ###12###hello
            [1] => 12
            [2] => hello
        )

    [1] => Array
        (
            [0] => ###43###good
            [1] => 43
            [2] => good
        )

    [2] => Array
        (
            [0] => ###113###thefinalstring
            [1] => 113
            [2] => thefinalstring
        )

)

Upvotes: 0

Rinku
Rinku

Reputation: 1078

(.*?)###(\d*)###(.*?)([a-zA-Z]*)

Use this regex

Upvotes: 1

Related Questions