preg match - PHP preg_match for multi language -


preg_match( '/^[-a-za-z0-9\p{han}]+$/u', $name) 

this work chinese character, need check languages. suggestions?

i tried below command. works language but, doesn't work all.

preg_match('/^[-a-za-z0-9\p{l} ]+$/u', $name) 

edit

the exact requirement be: if string contains symbol, replace _; while allowing multi language content.

the exact requirement be: if string contains symbol, replace _; while allowing multi language content.

so, need use preg_replace replaces non-overlapping occurrences of pattern defined replacement string, , pattern match symbol \p{s}. not forget u unicode modifier.

preg_replace('~\p{s}~u', '_', $s); 

now, if plan match , remove punctuation chars (posix character class [:punct:] includes both punctuation , symbols) exception of -, may use

preg_replace('~(?!-)[[:punct:]]~u', '_', $s); 

see regex demo.

here, (?!-) negative lookahead restrict more generic [[:punct:]] pattern matches punctuation , symbol chars forcing regex engine exclude - matching.

you may add more exceptions way if necessary.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -