Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with reg expression

Status
Not open for further replies.

litton1

Technical User
Apr 21, 2005
584
GB
Hi all, please could you give me some help with this regular expression?
I am (trying) using preg_match to see if there are any illegal operators in a string but think I may be using the regular expression wrong

Code:
$pattern = '^["/OR/"]| ["/AND/"]|["/And/"]| ["/\+/"]|["/\&/"]|["/\'/"]| ["/#/"]$';
$badOper = preg_match($pattern, $strToCheck);

but i obviously don’t want words like Andrea, ordinance to show up

A problem with no solution is a problem viewed from the wrong angle
 
i still dont get the use of the REgExp can u be a bit more clear???

Known is handfull, Unknown is worldfull
 
Yes sorry, I don’t want any of the words such as ‘AND’ ‘OR’ and I don’t want apostrophise, hash or equals etc. if any of these words or operators/symbols are in the string $strToCheck then true should be returned. Hope that is a bit clearer and thanks for your reply

A problem with no solution is a problem viewed from the wrong angle
 
why not use strpos()

Known is handfull, Unknown is worldfull
 
try
Code:
$pattern = "/\band\b|\bor\b|[\'\#\=\+]/i";
$badOper = preg_match($pattern, $strToCheck);

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Hi again and thanks for both of your replies. I think vbkris, using strpos() would be faster in this instance but I wanted to use a reg expression as I need the practice :-( , that did the trick thanks jemminger, I can take that now and make it fit my needs. Thanks again both of you

A problem with no solution is a problem viewed from the wrong angle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top