Jump to content

preg_match regex and single quotes


monkeytooth

Recommended Posts

$pattern = '#^[a-z0-9\x20]+$#i'; if(preg_match($pattern, $ChkqString)

 

So far I have all I want to do with this regex statement working (alphanumeric with spaces allowed) but I want to also allow single quotes cause some of the search terms I need to allow people to look up contain a ' in it. (alternatively is there a way to block multiple instances of ' back to back?

 

Im not good with regex, so any help i would appreciate

Link to comment
https://forums.phpfreaks.com/topic/187686-preg_match-regex-and-single-quotes/
Share on other sites

Adding support for single quotes is as simple as placing one in the character set (just bare in mind that since your string is delimited by single quotes you will need to escape it). If you really want to allow only 1 in a row it will complicate the pattern rather a lot but I'm sure is possible.

 

'#^[a-z0-9\x20\']+$#i'

Don't really want to allow only one per row, but not allow ' x2 like '' but if its going to complicate things I can most likely just use something else to search specificly for tht in the string after the string runs through preg_match

 

delimiting by double quotes inst a problem either, I should probably do that anyway to prevent php from trying to say something is when its not. like the $

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.