Ravindra S
Ravindra S

Reputation: 49

Need clarification on preg_match in PHP

I'm kinda of new to PHP, can you please clarify about the below preg_match.

preg_match("/^(9)\1+$/",$value);

Upvotes: 1

Views: 91

Answers (2)

alex
alex

Reputation: 490183

It will match a string that consists of two or more 9s.

The regex is weird, and not typical of its intention IMO. I'd write it as...

/^9{2,}\z/

Upvotes: 4

user237865
user237865

Reputation: 1250

preg_match($arg1, $arg2);

$arg1 - regular expression $arg1 is being searched/matchedin $arg2

for more help refer this link: http://php.net/manual/en/function.preg-match.php

for regular expressions: http://www.regular-expressions.info/examples.html

In the example you gave: The regular expression "/^(9)\1+$/" - Starts(^) with 9 and have more than 1 (\1+ which means 2 or more) 9's and ends($) with 9

So this is being searched in the $value. Hope it is clear.

Upvotes: -1

Related Questions