Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001032

Re: [PHP] Quick RegEx Question From: Jon Jacob (jonjacobmoon <email protected>)
Date: 03/31/01

Jeff Oien wrote:

> I want to check if a variable contains a price, like
> $19.99
> It definitely would be a dollar sign, two integers a dot and
> two integers. Here is what I tried which doesn't work.
>
> if (ereg("\$([0-9]{2}).([0-9]{2})", $Price))
> or
> if (ereg("\$([0-9]{2})\.([0-9]{2})", $Price))
>
> Thanks.
> Jeff Oien
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe <email protected>
> For additional commands, e-mail: php-general-help <email protected>
> To contact the list administrators, e-mail: php-list-admin <email protected>

I am not an expert on PHP but I have been programming in Perl for four
years so I can tell you what I would use in Perl and you can see if that
works in PHP. (I am almost sure they would be the same...)

/\$\d\d\.\d\d\.d/

It looks to me like you are forgetting to escape your period making the
interpreter think it is "any character" rather than a literal period. I am
not sure what the {2} is because I have never used that. Does that part of
it really work that way?

Good luck, hope that helps.

_________________________________________________________
Do You Yahoo!?
Get your free  <email protected> address at http://mail.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>