Connecting Tech Pros Worldwide Forums | Help | Site Map

ereg question

monomaniac21
Guest
 
Posts: n/a
#1: Jan 26 '07
hi all

can anyone tell me, does this condition evaluate to true or false?

$foo = ereg('ca?t', 'caaaaaaat');

thanks

marc


Rik
Guest
 
Posts: n/a
#2: Jan 26 '07

re: ereg question


monomaniac21 <mcyi2mr3@googlemail.comwrote:
Quote:
hi all
>
can anyone tell me, does this condition evaluate to true or false?
>
$foo = ereg('ca?t', 'caaaaaaat');
False afaik. Forget the POSIX functions, use preg_match();

To match 'cat' or 'ct':
preg_match('/ca?t/',$string);

To match 'cat', 'caat','caaat' etc.
preg_match('/ca+t/',$string);

To match 'ct','cat', 'caat','caaat' etc.
preg_match('/ca*t/',$string);
--
Rik Wasmus
mvandenb@gmail.com
Guest
 
Posts: n/a
#3: Jan 26 '07

re: ereg question


Regex reference:
http://en.wikipedia.org/wiki/Regular_expression
It basic but it works.


'ca?t' translated in to English:

find the string 'ct' or 'cat'

? - match 1 or 0 occurrences

+ - match 1 or more occurrences 'cat' 'ca...at'

* - match 0 or more occurrences 'ct' 'cat' 'ca...at'

There is more but see the link above.

kenleycapps@gmail.com
Guest
 
Posts: n/a
#4: Jan 28 '07

re: ereg question


If you're looking to interactively test regex, why not use something
like Regex Coach? http://weitz.de/regex-coach/

Very good tool. I can't live without it. Windows only though, as far
as I know.

On Jan 26, 2:01 pm, mvand...@gmail.com wrote:
Quote:
Regex reference:http://en.wikipedia.org/wiki/Regular_expression
It basic but it works.
>
'ca?t' translated in to English:
>
find the string 'ct' or 'cat'
>
? - match 1 or 0 occurrences
>
+ - match 1 or more occurrences 'cat' 'ca...at'
>
* - match 0 or more occurrences 'ct' 'cat' 'ca...at'
>
There is more but see the link above.
Closed Thread


Similar PHP bytes