473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

ereg & preg_match

Hi all,

Even having read the PHP Manual, I can't understand the difference between
the ereg function and the preg_match...

Could anyone help ?

thx in advance,

--
pomho
Jul 17 '05 #1
2 4434
On Sat, 20 Mar 2004 16:38:54 +0100, "pomho" <po***@nospam.org> wrote:
Even having read the PHP Manual, I can't understand the difference between
the ereg function and the preg_match...


ereg uses POSIX extended regular expressions - these are defined by a standard
Unix specification, but have some limitations in what they can do.

preg_match uses PCRE (Perl Compatible Regular Expressions), which use the more
powerful and typically faster Perl-style expressions; the basics are the same,
but there's more pattern match expressions available in PCRE which means you
can match more complex expressions that would be awkward or just not possible
with ereg.

Unless you have a good reason otherwise, preg_match is preferred.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2
> ereg uses POSIX extended regular expressions - these are defined by a
standard
Unix specification, but have some limitations in what they can do.

preg_match uses PCRE (Perl Compatible Regular Expressions), which use the more powerful and typically faster Perl-style expressions; the basics are the same, but there's more pattern match expressions available in PCRE which means you can match more complex expressions that would be awkward or just not possible with ereg.

Unless you have a good reason otherwise, preg_match is preferred.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


Thanks you for your quick answer !

--
pomho
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Is there some way of using ereg to detect when certain filename extensions are supplied and to return false if so, WITHOUT using the ! operator before ereg () ? I have an API that allows as an...
3
by: Aphrael | last post by:
Hello all, last time, ereg specialists did help me, so I ask again: base pattern: some texte her result: the number alone So ? any idea ? Aphrael ;-)
3
by: news | last post by:
I'm trying to make sure a form has only one or two digits in either of two fields. I looked at php.net and http://www.regular-expressions.info/reference.html and this is what I put together, but...
18
by: yawnmoth | last post by:
Say I have the following script: <? $string = 'test'; if (eregi("^+$",$string)) { echo 'matches!'; } else {
6
by: Cerebral Believer | last post by:
Is this a good ereg statement? if (!ereg("^+(\.+)*@+(\.{1,})*\.({2,}){1}$",$email_1 or $email_2)) { unset($_GET); $message_new = "<font color='#cc0000'>$email_1 or $email_2 is not a valid...
4
by: ollie.mitch | last post by:
Hi, I need two ereg expressions in my PHP code. One of them needs to check that a string only contains letters, and the other needs to check that the string only contains letters and commas...
2
by: dkirkdrei | last post by:
I am having a problem verifying characters in a variable, I am trying to create a conditional statement based on whether or not the first two characters of a variable contain "E9". The variable...
3
by: monomaniac21 | last post by:
hi all can anyone tell me, does this condition evaluate to true or false? $foo = ereg('ca?t', 'caaaaaaat'); thanks marc
3
by: wizardry | last post by:
hello - i need to convert this string to preg_match to support current version of php. i have googled and found some info but still get an error where it doesnt like my search string. if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.