remove_punctuation¶
- pyhelpers.text.remove_punctuation(input_text, rm_whitespace=True, preserve_hyphenated=True)[source]¶
Removes punctuation from textual data.
- Parameters:
input_text (str) – The input text from which punctuation will be removed.
rm_whitespace (bool) – Whether to remove whitespace characters as well; defaults to
True
.preserve_hyphenated (bool) – Whether to preserve hyphenated words; 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!', preserve_hyphenated=False) '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'