regex - PHP regular expression to match words -
ok, i've been wrestling regex ages , can't work.
what want do:
given string want array of strings containing words, each preceded non-word characters.
example input string:
one "two" (three) -four-
the words in string may anything, gibberish, amount of punctuation or symbols.
what see:
array: 1 "two " (three ) -four -essentially, each match lastly thing word, preceded left on previous match.
as noted in questions title using in php, have tried various combinations of preg_match_all() , preg_split(), patterns containing many variations of "\w", "\b", "[^\w]" , on.
the bigger picture
essentially want place * after each word in string searching purposes.
i not regex person, help appreciated!
if want add together asterisk after each "word" this:
<?php $test = 'one "two" (three) -four-'; echo preg_replace('/(\w+)/', "$1*", $test); ?>
http://phpfiddle.org/main/code/8nr-bpb
php regex
No comments:
Post a Comment