R
R
Refic2015-12-19 16:32:01
Python
Refic, 2015-12-19 16:32:01

How to remove punctuation in python but leave some characters?

Hello.
How to remove punctuation in python, but leave some characters in a string?
The line, for example, is like this - "blah. ! blah (beeep?) heap :) :) :)
I remove characters like this print re.sub(r'[^\w\s]', '', text),
but how should I leave emoji at the end?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2015-12-19
@Refic

you want to remove non-alphabetic characters and leave non-alphabetic characters...
this is not done with one expression
or solve the problem in a direct pass in three stages
1) clearing non-unicode (you may not need a stage) 2
) clearing unnecessary
characters
three steps
1) replace emoticons with sequences
2) cleanup
3) replace sequences with emoticons
in three steps faster

V
Vladimir, 2015-12-19
@vintello

look here for such a combination x(?!y) as well as an operator like |

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question