regex - php - split by unknown regular expression -


i need split string seperators known me , unknown. example know want split string "\n" , "," , "." 1 sperator can user defined: example can ";" or "hello" or pretty anything.

i tried this:

"[\n|,|.|".$exp."]" 

...but didnt work expected. understand | means or. reg exp should split "\n" or "," or "." or "hello". think because if try [hello] splits every letter, not whole word. thats strange because if try [\n] splits "\n" - not "\" or "n".

can please explain me? :)

when place bunch of characters in character class, in [hello], defines token matches 1 character either h, e, l or o. also, | has no meaning inside of character class - it's matched normal character.

the correct solution isn't use character class - meant use normal brackets:

(\n|,|\.|".$exp.")

by way - make sure escape regex metacharacters in $exp. basically, full list here needs escaped backslashes: http://regular-expressions.info/reference.html there may helper function you.

edit: since you're not using character class, need escape \ . metacharacter meaning 'match 1 of anything'. forgot.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -