Welcome Guest, Not a member yet? Register   Sign In
regular expression is not working
#1

[eluser]samitrimal[/eluser]
Hi i have a problem in using dollor sign in my regular expression . When i dont use dollar sign it works fine.Here is a code
Code:
$pattern="/^[^0-9][0-5a-zA-Z]{1,}([a-zA-Z0-9_|-])*$/";
if (preg_match($pattern, "a12-|", $matches)) {
  echo "Match was found <br />";
  echo $matches[0];
}
else{
  echo "Pattern does not match";
}
The error occours when i use dollor sign.
Code:
$pattern="/^[^0-9][0-5a-zA-Z]{1,}([a-zA-Z0-9_|-$])*$/";
if (preg_match($pattern, "a12-|$", $matches)) {
  echo "Match was found <br />";
  echo $matches[0];
}
else{
  echo "Pattern does not match";
}
I encountered the following error
Code:
Warning: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 36 in E:\wamp\www\graph\testpractice\php\regex\pregmath.php on line 3
need help to solve this problem
#2

[eluser]theprodigy[/eluser]
Quote:The error occours when i use dollor sign.
Code:
$pattern="/^[^0-9][0-5a-zA-Z]{1,}([a-zA-Z0-9_|-$])*$/";
if (preg_match($pattern, "a12-|$", $matches)) {
  echo "Match was found <br />";
  echo $matches[0];
}
else{
  echo "Pattern does not match";
}
The $ is a special character in Regex.
Try putting a backslash before the $ in your $pattern;
Code:
$pattern="/^[^0-9][0-5a-zA-Z]{1,}([a-zA-Z0-9_|-\$])*$/";
if (preg_match($pattern, "a12-|$", $matches)) {
  echo "Match was found <br />";
  echo $matches[0];
}
else{
  echo "Pattern does not match";
}
#3

[eluser]InsiteFX[/eluser]
Here is a good regular expression utility that I found!

Regular Expression tester

If you look at the bottom right side you can download a desktop version of it.

InsiteFX
#4

[eluser]samitrimal[/eluser]
thank u InsiteFX this tool is great and everyone .




Theme © iAndrew 2016 - Forum software by © MyBB