Page 1 of 1

I dont get it - preg_split patterns?

Posted: Tue Feb 03, 2004 2:35 am
by Stryks
Hi all,

I'm just wonderinf if someone could explain simply how the heck these things work.

I'm just trying to split a string on either a space or a comma, so I look up help on preg_split, but I cant make heads or tails of how the pattern relates to what it is supposed to find.

For example, it says that a pattern of '/[\s,]+/' is going to find 'commas or space characters which include " ".'

Whaaa?!?

Please ... can anyone help me understand this. I've come across it before in a few other functions and I just cant seem to find any info on what it all means.

Thanks

Posted: Tue Feb 03, 2004 6:17 am
by Stryks
No help?

Even just an idea of where to get an explaination would be great.

Posted: Tue Feb 03, 2004 7:19 am
by patrikG
RegEx are the evil dragon in the realm of programming. But once you've got to know them a bit, they are extremely powerful (bit like a dragon).

There are plenty of tutorials about, just google for them - I remember I found one on phpbuilder.com quite useful.

Regarding the patterns itself - have a look at "Pattern Syntax" in the manual: http://uk.php.net/pcre.pattern.syntax

\s means any whitespace character, btw.