Jump to content


Photo

PHP Manual Example


  • Please log in to reply
2 replies to this topic

#1 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 September 2006 - 10:08 PM

According to the PHP manual, the following code should produce "Matched".

<?php

$string = "sense and sensibility";

if (preg_match("/(sens|respons)e and \1ibility/", $string)){
	echo "Matched";
}
else {
	echo "No match made";
}
?>

But it doesn't.  It tells me, No match made.  Anyone tell me if I'm missing something here?  Have I overlooked something obvious.  Can I only use back referencing in certain versions of PHP?

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 14 September 2006 - 10:59 PM

Either change the double quotes surrounding your pattern to single quotes, or escape the backslash.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 15 September 2006 - 08:30 AM

Thanks effigy...

I have another question, but I'll post it in a new topic with a new title.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users