SoFunction
Updated on 2024-11-12

Python implementation of replacing multiple spaces with one space.md

Recently encountered this problem in text preprocessing, the solution is as follows:

import re
str1 = ' rwe fdsa  fasf  '
str1_after = (' +', '', str1)
print(str1_after)

Further, multiple numbers can be converted to a specific symbol such as 'num', this step is also commonly used in natural language preprocessing because sometimes we don't care what the number is, just whether it is a number or not.

import re
str1 = 'My phone number 1888888888888,email 1111111@'
str1_after = ('\d+', 'num', str1)
print(str1_after)

Above this Python implementation of multiple spaces to a space.md is all I have to share with you, I hope to give you a reference, and I hope you support me more.