Hard Light Productions Forums

Off-Topic Discussion => General Discussion => Topic started by: Sandwich on November 14, 2003, 06:36:52 am

Title: Anyone Know Perl Regular Expressions?
Post 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?
Title: Anyone Know Perl Regular Expressions?
Post by: Sandwich on November 14, 2003, 07:27:45 am
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
Title: Anyone Know Perl Regular Expressions?
Post by: Styxx on November 14, 2003, 07:40:26 am
* points and laughs *
Title: Anyone Know Perl Regular Expressions?
Post by: Goober5000 on November 14, 2003, 07:59:37 am
What about the Wiki pregexps? :)
Title: Anyone Know Perl Regular Expressions?
Post by: ZylonBane on November 14, 2003, 09:22:31 am
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
Title: Anyone Know Perl Regular Expressions?
Post by: Sandwich on November 15, 2003, 05:55:36 pm
Quote
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. ;)