This seems to be the worst documented area of learning PHP imaginable. Are there any decent tutorials about? Most seem to talk about ereg() which is no longer relevant or are relevant but horrifically complex and not designed for people like me with no real understanding of the subject. There must be some kind of decent introduction somewhere?
In the meantime, anyone fancy being a star and writing one to match
100-299:1.25
The numbers are of any length but can only be numbers. The other characters ( - : . )have to be exact though.
Until now I’ve always managed to avoid regexes and fumble about with str_replace etc but I give in and I need to learn how to use these scary things! Any help appreciated.
I realized it isn’t an amazingly well documented area either, in comparison to the other areas anyway, so I learned it the broken way, this should work, but is probably flawed.
To me regex is like a whole other language. One the hardest things to master is to not only get what you want to get, but to also not get what you want not to get. eg. try
Just out of curiousity I benchmarked 1,000,000 times regex vs 1,000,000 sscanf for the var $var='100-299:1.25'; and regex takes 3.7137291431427 seconds, while sscanf only takes 1.7851250171661, so it only need about 48% of the time the regex needs! I like sscanf!
Off Topic:
I didn’t say that to bash you, you know that right? Just found it funny is all
I’m intrigued as to why you both feel that the documentation is lacking. The section of the PHP manual on PCRE goes into a lot of depth, especially describing the syntax to use, and covers more than most folks will ever use in their day-to-day regexing (not a real word)… at least that was what I thought until reading this thread!
www.regular-expressions.info is one of better resources when it comes to introduction to regexps.
As Salathe already hinted, php itself has nothing to do with actual regexps and how to construct them as the topic is vast in itself and not tied into the manual about php functions using those.