Answers for "string.punctuation"

1

python pad punctuation with spaces

# Basic syntax using regex:
import re
re.sub('characters_to_pad', r' \1 ', string_of_characters)
# Where you can specify which punctuation characters you want to pad in
#	characters_to_pad

# Example usage:
import re
your_string = 'bla. bla? bla.bla! bla...' # An intelligent sentence
your_string = re.sub('([.,!()])', r' \1 ', your_string)
# your_string is updated in place
print(your_string)
--> bla .  bla? bla . bla !  bla .  .  . 
# Notice that the '?' didn't have spaces added because it wasn't listed
#	among the characters_to_pad in the above function
Posted by: Guest on December-15-2020
1

can you edit string.punctuation

>>> name = '\\test-1.'
>>> valid_characters = 'abcdefghijklmnopqrstuvwxyz1234567890- '
>>> filtered_name = ''.join([ x for x in name if x.lower() in valid_characters ])
>>> print(filtered_name)
test-1
Posted by: Guest on November-27-2020
-1

replace all punctuation in string java

inputString.replaceAll("\\p{Punct}", "");
Posted by: Guest on December-25-2019

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language