how can I make sure a certain keyword just occurs once in the input with regular expression?
I think there is some mistakes in the expression below as I can repeat the same keywords,
if (!preg_match('/\b(.php?){1}\b/', $cfg_path))
{
$error = true;
echo '<error elementid="cfg_path" message="PATH - make sure you have a \'.php?\' in the path."/>';
}
I just want this to be true,
form.php?category=something or form.php?
but not this,
form.php?.php?category=something or form.php?.php?
please let me know how to fix it.
thanks.
You are on the right track. You need to espace special characters in regext. the ? is a special character and should be escaped using the \?, also the dot should be escaped with slash too.
Finally, you should not use the \b option, it is not applicable in your situation.
Try: