Forum Moderators: coopster

Message Too Old, No Replies

No more ereg regular expressions!

Regular Expression (POSIX Extended) deprecated

         

coopster

6:59 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Guess what? The following functions have gone bye-bye in PHP 5.3:
  • ereg_replace [php.net] — Replace regular expression
  • ereg [php.net] — Regular expression match
  • eregi_replace [php.net] — Replace regular expression case insensitive
  • eregi [php.net] — Case insensitive regular expression match
  • split [php.net] — Split string into array by regular expression
  • spliti [php.net] — Split string into array by regular expression case insensitive
  • sql_regcase [php.net] — Make regular expression for case insensitive match


Note: As of PHP 5.3.0 this extension is deprecated, calling any function provided by this extension will issue an
E_DEPRECATED
notice.

I read this today on the POSIX Regex Functions [php.net] manual page. I never did use them, personally. For regular expressions I have always been partial to the Perl-compatible syntax so I use the PCRE functions [php.net].

The 5.3 release wiki [wiki.php.net] also states "No longer allow to disable" PCRE. Looks like the development team has standardized on a single regular expression engine for the future.

Your thoughts?

eelixduppy

7:14 pm on Jan 22, 2009 (gmt 0)



I honestly never found too much use for these myself. I've always stuck to PCRE, as well, which IMO is what should be used now.

janharders

7:18 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what would be really, really great is if they went more "perl compatible", not just in terms of the general syntax, but also about modifiers etc pp ;)

Receptional Andy

7:21 pm on Jan 22, 2009 (gmt 0)



I think it's a good thing - for one reason or another, I started out using the ereg functions as opposed to preg_match, but I eventually discovered the limitations myself and switched over (plus /i has to be better than a whole different function name!).

My feeling is that there might be a slightly higher learning curve for PCRE, but that the process is certainly worth it. And that syntax is much more interoperable than POSIX these days.

coopster

7:26 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually, it is more advanced than you realize, janharders. The docs are way behind, function is there. You can use phpinfo() to see which library version you have available and knowing that, you have any of the modifiers from that engine available. I've been using modifiers for years that are still not in the PHP docs.

janharders

7:41 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thank you, coopster.
I've never really tested all that's possible, I just stumbled over some modifier a couple of weeks back that was inconsistent with the perl way - and I found that odd, given that it should be the perl compatible thingy.
I've personally never used the POSIX-regexps in php, so it's fine with me.

coopster

8:03 pm on Jan 22, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Yes, there are indeed some Perl differences [php.net] that can be *gotchas* so you have to stay on your toes. Mostly they have to do with assertions and greediness though and once you can log into memory how PHP does things in this regard you will be on your merry way.

Also note that on that page it refers to

Perl 5.005
where as the current version shipping in PHP 5.2.8 is version 7.8!

bkeep

1:32 am on Jan 23, 2009 (gmt 0)

10+ Year Member



Perl is v5.10.0 and the PCRE library is v7.8
Sorry I cleaned the dust off my monitor.

I too think it is good move, one less thing to try and remember I started out with ereg and the POSIX regex stuff for no other reason then I didn't know any better.

I really think a lot of the php tutorials available on the net had been written a long long time ago and instead of updating the code to current best practices the site ops just left it up since it got good traffic or pure laziness.

I am still in the process of learning best practices but it takes a lot of work to find the good or right solution so I think that having one less choice when you don't know what to choose or why is a good thing.

coopster

2:30 pm on Jan 23, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Perl is v5.10.0 and the PCRE library is v7.8

Yes, thanks for catching that, bkeep. I read the documentation as referring to the PCRE library version where as it is seemingly referring to the version of perl itself. And we certainly don't need to be any more confused!

Which in turn reminded me of something to note for janharders and others reading this thread. If you find yourself pondering "how can I know which modifiers and switches are available to me in the pcre functions?", the answer is found in your php version configuration. Check the pcre library installed for your current PHP version (run a phpinfo() script and search the page for "pcre") and then check the pcre man page [pcre.org]. A short little sentence in the first paragraph ties it together for you ...

The current implementation of PCRE (release 7.x) corresponds approximately with Perl 5.10

Knowing that, I assumed correctly that I could use some of the *new* pcre modifiers that I was reading in the

perlre
perldoc pages that I needed in some of my work. This was how I first figured out that they were available to me.