top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

preg_match in PHP?

+2 votes
18 views

Is this correct syntax?

case preg_match("/^[-1|delete|hide|save]/", $MassOption) !== 1 :

I am needing to test against -1 (negative 1) and the words delete, hide, and save. $MassOption should not equal those.

posted Sep 22, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

+1 vote

No, in regular expressions, the [ ] are for matching individual characters, not strings. You could instead perform a standard match in () and just negate the result of preg_match() with a !.

answer Sep 22, 2015 by Honey
I did finally come across the () however the ! eluded me. Wherein do I place the ! mark? Like so?

preg_match("/^![-1|delete|hide|save]/", $MassOption) !== false

or just?

preg_match("/^![-1|delete|hide|save]/", $MassOption)
You wouldn't place it in your Regex, you use it to negate your call to preg_match:

!preg_match()

And get rid of the square brackets, they are for character matches, not string matches.
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...