php - Matching regular and dash separated word with regex -


i want match words seperated dash - , regular word. i'm using regular expression \b(word|someother|xyz|....|word50)\b // upto 50 words trouble want match words

w-ord w-o-r-d some-oth-e-r x-y-z 

so instead of putting (-)? after every character manually this

\b(w(-)?o(-)?r(-)?d|w(-)?o(-)?r(-)?d|someother|....|word50)\b 

is there shorter way regex can match - also. list long want shorter way

you can match this:

$regex = '#\b(word|someother|xyz|....|word50)\b#'; $ret = preg_match($regex, preg_replace('#(?<=\w)-(?=\w)#', '', $str), $m); 

i.e. if dash comes between 2 word characters remove dash (hyphens) strings first , match.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -