Quick question - preg_match

hey guys i got the following preg_match

preg_match('/[^a-z0-9 ]/i', $title)

which checks if there’s space / a-z / 0-9 in the string…

Now i want to add another character ‘|’, where in the code above do i need to add it so it’ll work properly?

Have you actually tried just sticking it in there next to the other characters you’re checking for?

PS: This function as written will check if there’s anything EXCEPT a-zA-Z0-9 and space in the string.

PS: This function as written will check if there’s anything EXCEPT a-zA-Z0-9 and space in the string.

Yeah thats what i meant, my bad :stuck_out_tongue:

Have you actually tried just sticking it in there next to the other characters you’re checking for?

Yes i tried it like this:

preg_match('/[^a-z0-9| ]/i', $title)

didnt seemed to work thought

So you put in “This is a | test” and it comes out with a number?

hmm u right with ur example it does work, i tried with an example in hebrew which didnt, probably encoding issue, ill have to take a deeper look

nother question regarding this, if i want to adda also ‘-’ character, ill have to do it like that? ‘\-’

So you put something in that wasnt in [a-zA-Z0-9| ] and it came out with a number that wasnt -1. Sounds like it did exactly what it’s supposed to.

To add - to the pattern, yes, you would have to escape it as \-

Just because I learned so much there, some related links…

Wonderfull tool to learn and test regex
http://gskinner.com/RegExr/
give it a try and put it in bookmarks - I use it reguarly…

also usefull
http://txt2re.com/

regards
Hensel