I have a list of strings. Some of them contain commas, single quotes, etc. Is there a quick way to replace those characters by blanks? My list looks something like this:
list = {"string1", "bla,bla", "more'stuff", "and more;stuff"}
cheers
Use
StringReplace[list, PunctuationCharacter -> " "]
(* {"string1", "bla bla", "more stuff", "and more stuff"} *)
PunctuationCharacter
is new in version 10.3. The 10.x updates received many new functions for text processing. In older versions I would use an explicit list of possible punctuation characters, i.e.
punctuation = Alternatives@@Characters[",.?:;'\"!-"]
I'm pretty sure I missed some.
StringReplace[list, punctuation -> " "]
(* {"string1", "bla bla", "more stuff", "and more stuff"} *)
StringReplace[list, RegularExpression["[[:punct:]]"] -> " "]
.
$\endgroup$
Commented
Oct 27, 2015 at 10:59