3

I have a string such as brown,Ceilings,flu,hydraulic bar stool,horse saddles,marble tiles. I want to remove the text that does not contain spaces, but keep the text that has at least one space. The result should be like hydraulic bar stool,horse saddles,marble tiles.

I'm stuck at [^,]*\s and still don't know how to figure out the problem. How can I do this with a regex find and replace?

1
  • What have you tried? What did you Google? Super User is not a script writing service. People will be more likely to help you if you have something to go off of.
    – Cfinley
    Aug 14, 2014 at 13:22

1 Answer 1

0

Find

(?<! )\b[^, ]+(,|$)

Replace with nothing.

How it works:

\b[^, ]+ matches entire words.
(?<! ) limits these matches to words that are not preceded by a space.
(,|$) further limits the matches to words that are followed by a comma or the end of the line.

This should match all single-word entries and the trailing comma.

1
  • to save anyone else having to google, \b marks the beginning or end of a word.
    – localhost
    Aug 9, 2018 at 0:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .