Author Topic: Anyone Know Perl Regular Expressions?  (Read 931 times)

0 Members and 1 Guest are viewing this topic.

Offline Sandwich

  • Got Screen?
  • 213
    • Skype
    • Steam
    • Twitter
    • Brainzipper
Anyone Know Perl Regular Expressions?
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?
SERIOUSLY...! | {The Sandvich Bar} - Rhino-FS2 Tutorial | CapShip Turret Upgrade | The Complete FS2 Ship List | System Background Package

"...The quintessential quality of our age is that of dreams coming true. Just think of it. For centuries we have dreamt of flying; recently we made that come true: we have always hankered for speed; now we have speeds greater than we can stand: we wanted to speak to far parts of the Earth; we can: we wanted to explore the sea bottom; we have: and so  on, and so on: and, too, we wanted the power to smash our enemies utterly; we have it. If we had truly wanted peace, we should have had that as well. But true peace has never been one of the genuine dreams - we have got little further than preaching against war in order to appease our consciences. The truly wishful dreams, the many-minded dreams are now irresistible - they become facts." - 'The Outward Urge' by John Wyndham

"The very essence of tolerance rests on the fact that we have to be intolerant of intolerance. Stretching right back to Kant, through the Frankfurt School and up to today, liberalism means that we can do anything we like as long as we don't hurt others. This means that if we are tolerant of others' intolerance - especially when that intolerance is a call for genocide - then all we are doing is allowing that intolerance to flourish, and allowing the violence that will spring from that intolerance to continue unabated." - Bren Carlill

 

Offline Sandwich

  • Got Screen?
  • 213
    • Skype
    • Steam
    • Twitter
    • Brainzipper
Anyone Know Perl Regular Expressions?
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
SERIOUSLY...! | {The Sandvich Bar} - Rhino-FS2 Tutorial | CapShip Turret Upgrade | The Complete FS2 Ship List | System Background Package

"...The quintessential quality of our age is that of dreams coming true. Just think of it. For centuries we have dreamt of flying; recently we made that come true: we have always hankered for speed; now we have speeds greater than we can stand: we wanted to speak to far parts of the Earth; we can: we wanted to explore the sea bottom; we have: and so  on, and so on: and, too, we wanted the power to smash our enemies utterly; we have it. If we had truly wanted peace, we should have had that as well. But true peace has never been one of the genuine dreams - we have got little further than preaching against war in order to appease our consciences. The truly wishful dreams, the many-minded dreams are now irresistible - they become facts." - 'The Outward Urge' by John Wyndham

"The very essence of tolerance rests on the fact that we have to be intolerant of intolerance. Stretching right back to Kant, through the Frankfurt School and up to today, liberalism means that we can do anything we like as long as we don't hurt others. This means that if we are tolerant of others' intolerance - especially when that intolerance is a call for genocide - then all we are doing is allowing that intolerance to flourish, and allowing the violence that will spring from that intolerance to continue unabated." - Bren Carlill

 

Offline Styxx

  • 211
    • Hard Light Productions
Anyone Know Perl Regular Expressions?
* points and laughs *
Probably away. Contact through email.

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Anyone Know Perl Regular Expressions?
What about the Wiki pregexps? :)

  

Offline ZylonBane

  • The Infamous
  • 29
Anyone Know Perl Regular Expressions?
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
ZylonBane's opinions do not represent those of the management.

 

Offline Sandwich

  • Got Screen?
  • 213
    • Skype
    • Steam
    • Twitter
    • Brainzipper
Anyone Know Perl Regular Expressions?
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. ;)
SERIOUSLY...! | {The Sandvich Bar} - Rhino-FS2 Tutorial | CapShip Turret Upgrade | The Complete FS2 Ship List | System Background Package

"...The quintessential quality of our age is that of dreams coming true. Just think of it. For centuries we have dreamt of flying; recently we made that come true: we have always hankered for speed; now we have speeds greater than we can stand: we wanted to speak to far parts of the Earth; we can: we wanted to explore the sea bottom; we have: and so  on, and so on: and, too, we wanted the power to smash our enemies utterly; we have it. If we had truly wanted peace, we should have had that as well. But true peace has never been one of the genuine dreams - we have got little further than preaching against war in order to appease our consciences. The truly wishful dreams, the many-minded dreams are now irresistible - they become facts." - 'The Outward Urge' by John Wyndham

"The very essence of tolerance rests on the fact that we have to be intolerant of intolerance. Stretching right back to Kant, through the Frankfurt School and up to today, liberalism means that we can do anything we like as long as we don't hurt others. This means that if we are tolerant of others' intolerance - especially when that intolerance is a call for genocide - then all we are doing is allowing that intolerance to flourish, and allowing the violence that will spring from that intolerance to continue unabated." - Bren Carlill