RegEx. How to remove the space after the period before the punctuation character

I have a regular expression question. Suppose I have this line

"She gained about 55 pounds in...9 months. She was like an eating machine. "Trump, a man who wants to be president: "

I want to remove every empty space for the period and before the symbol "and delete the symbol"

For example, this part of the sentence

She was like an eating machine. "Trump, a man who wants to be president: 

should become

She was like an eating machine.Trump, a man who wants to be president: "

Thanks guys, regex isn't easy to find out. Appreciate any help! so far ps I am using R software, but I think it doesn’t matter, since regex works in every programming language

UPDATE

I solved my problem and I would like to share it, maybe it can help someone else. I have this dataset downloaded from kaggle about trump card and tweets.

Knime ( ). , gsub. , , , csv R UTF-8. , Knime

0
3

(1 ) ,

x <- "She gained about 55 pounds in...9 months. She was like an eating machine. "Trump, a man who wants to be president: "
gsub("\\.\\s+"", ".", x)
## => [1] "She gained about 55 pounds in...9 months. She was like an eating machine.Trump, a man who wants to be president: "

\\. , \\s+ 1 , " ".

regex demo R demo.

1 , :

gsub(". "", ".", x, fixed=TRUE)

R.

+4

, :

var str = 'She was like an eating machine. "Trump, a man who wants to be president. "New value'; 
str.replace(/\.\s"/g,".");
+1

http://regexr.com/ is a great tool for training and testing regular expressions.

The only thing I will add to Wiktor's answer is that it will not match "machine."Trump". To match any number of spaces after the period and before the quote, use the quantifier *:

x <- "She gained about 55 pounds in...9 months. She was like an eating machine. "Trump, a man who wants to be president: "
gsub("\\.\\s*"", ".", x)
0
source

Source: https://habr.com/ru/post/1693213/


All Articles