J
J
Jack4442020-08-09 11:32:06
Python
Jack444, 2020-08-09 11:32:06

How to remove a number along with adjacent characters with a regular expression?

When parsing, I encountered duplication. I get the same items but with an insert somewhere in the string as '1st', '2nd', '3rd', '4th' and in different languages ​​like French '6ème'.
I know that you can remove numbers through a regular expression using '\d'.
How can I immediately remove everything that comes after the number before the space?
It is possible to go through the whole thing in a loop, but maybe there is a more elegant way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-08-09
@Jack444

re.sub(r'\d+\S+', '', text)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question