monkeytooth Posted January 8, 2010 Share Posted January 8, 2010 $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 More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 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' Link to comment https://forums.phpfreaks.com/topic/187686-preg_match-regex-and-single-quotes/#findComment-990854 Share on other sites More sharing options...
monkeytooth Posted January 8, 2010 Author Share Posted January 8, 2010 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 $ Link to comment https://forums.phpfreaks.com/topic/187686-preg_match-regex-and-single-quotes/#findComment-990864 Share on other sites More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 Something like this should do the job... "#^(?:[a-z0-9 ]|(?<!')')+$#i"; Link to comment https://forums.phpfreaks.com/topic/187686-preg_match-regex-and-single-quotes/#findComment-990873 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.