I wanted to validate a string with preg_match but after a lot of struggle I just used if($str!='x'....
but just out of curiosity I wonna know how to do this using preg_match
I'm getting a string as an input-
the 1st char in the string must be %
the 2nd char must be space
the 3rd char must be a number
and the rest can be anything (special chars/numbers/letters..)
Jump to Post
Something like this should work.
/at the beginning and end of the pattern are delimiters.
^denotes the start of the line or string.
$denotes the end of the line or string. Thus everything between the
$must match the expression, as opposed …