punctuation

Match all punctuation not surrounded by alphanumeric characters?

Match all punctuation not surrounded by alphanumeric characters? Question: I am trying to write a regular expression that removes all non alphanumeric characters from a string, except for those that are surrounded by alphanumeric characters. For example, consider the following three examples. 1. it’s -> it’s 2. its. -> its 3. It’s a: beautiful day? …

Total answers: 2

Removing punctuations in dataframe using for loop

Removing punctuations in dataframe using for loop Question: I have a dataframe that looks like below A B C D E 0 Orange Dad’s X Eyes 3d. Navy 1 pink. Mum’s Bored. ooo. NaN 2 Yellow NaN Sad Gray NaN I’m trying to remove punctuations in every column in the dataframe using for loop import …

Total answers: 3

Extract substring from dot untill colon with Python regex

Extract substring from dot untill colon with Python regex Question: I have a string that resembles the following string: ‘My substring1. My substring2: My substring3: My substring4′ Ideally, my aim is to extract ‘My substring2’ from this string with Python regex. However, I would also be pleased with a result that resembles ‘. My substring2:’ …

Total answers: 3

Join split words and punctuation with punctuation in the right place

Join split words and punctuation with punctuation in the right place Question: So I tried using join() after splitting a string into words and punctuation but it joins the string with a space in between the word and punctuation. b = [‘Hello’, ‘,’, ‘who’, ‘are’, ‘you’, ‘?’] c = ” “.join(b) But that returns: c …

Total answers: 5

Best way to strip punctuation from a string

Best way to strip punctuation from a string Question: It seems like there should be a simpler way than: import string s = “string. With. Punctuation?” # Sample string out = s.translate(string.maketrans(“”,””), string.punctuation) Is there? Asked By: Redwood || Source Answers: Not necessarily simpler, but a different way, if you are more familiar with the …

Total answers: 32