I tried this, but it seems to work only with alphanumeric characters?
\ba\w*\b <- works
\b-\w*\b <- doesn't work
How can I remove all the words from a string that starts with a hyphen?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
preg_replace(“/-\w+/”, “”, “-000 aaa -bbb ccc -ddd -eee”)
gives:
aaa ccc
EDITED 3 times: As noticed in the comments – be it a stretch of the original question or not – all the suggested variants didn’t work with -xx-yy-zz or qq-ww-ee, or -äüö. This one :
… produced the following:
Limitations apply: accented characters are acceptable; multibyte ones would certainly be a stretch.