Hard Light Productions Forums
Off-Topic Discussion => General Discussion => Topic started by: Sandwich on November 14, 2003, 06:36:52 am
-
For a couple of reasons, I'm looking into learning the art of pregexps. Specifically (since I don't know Perl), the PHP implementation of pregexps.
So, can anyone telll me why the following code returns "No match"?
// Perl Regular Expression test
$string = "$string beginning with a dollar sign;";
if (preg_match("/^\$/",$string)) {
echo "Match!";
} else {
echo "No match!";
}
?>
It _should_ match if the first char (first signified by ^) is an actual $ sign (as signified by the escaped dollar sign in the expression, \$). But it doesn't.
I'm thinking either it's something to do with the dollar being seen, despite it being escaped, as an end-of-string marker, or as the beginning of a PHP variable somehow.
Anybody?
-
Gah, figured it out. I was forgetting that the $string part of the original variable would be evaluated as a variable itself, not as direct text. Stoooopeed me. :p
-
* points and laughs *
-
What about the Wiki pregexps? :)
-
FYI, in Perl they're just called regex's. None of this "pregexp" nonsense. And they're not unique to Perl. Several languages and shells support them.
http://etext.lib.virginia.edu/helpsheets/regex.html
-
Originally posted by ZylonBane
FYI, in Perl they're just called regex's. None of this "pregexp" nonsense. And they're not unique to Perl. Several languages and shells support them.
http://etext.lib.virginia.edu/helpsheets/regex.html
Yeah, I know but in PHP there are regexps, and there are pregexps, and since it's PHP we're dealing with here... ;) When in Rome and all that, y'know?
Goob, I'll look into that problem in a few minutes. ;)