remove_punctuation¶
- pyhelpers.text.remove_punctuation(x, rm_whitespace=True)[source]¶
Remove punctuation and optionally whitespace from textual data.
- Parameters:
x (str) – The input text from which punctuation will be removed.
rm_whitespace (bool) – Whether to remove whitespace characters as well; defaults to
True
.
- Returns:
The input text without punctuation (and optionally without whitespace).
- Return type:
str
Examples:
>>> from pyhelpers.text import remove_punctuation >>> remove_punctuation('Hello, world!') 'Hello world' >>> remove_punctuation(' How are you? ', rm_whitespace=False) 'How are you' >>> remove_punctuation('No-punctuation!') 'No punctuation' >>> raw_text = 'Hello world! This is a test. :-)' >>> remove_punctuation(raw_text) 'Hello world This is a test' >>> remove_punctuation(raw_text, rm_whitespace=False) 'Hello world This is a test'