保留句子的标点符号,但删除所有特殊字符的不敬信息Python

时间:2016-11-08 06:47:05

标签: python regex

我有来自html的文字。目前,我想保留句子的标点符号,但删除所有特殊字符的不敬信息(非句子)。

我尝试声明:

 sentences = re.sub('none', '', text)
 sentences = re.sub(ur"[^\w\d'\s]+", '', sentences.strip())
 print sentences

文本:

acting career of tom cruise started quite early but with a small role in the movie endless love (1981). however, he got his big break as a supporting actor in the movie taps later that year. in 1983, his movies risky business and all the right moves along with top gun in 1986 paved the path for tom cruise as an established actor and a superstar. after this there was no looking back and tom cruise went to star in many super-successful movies like cocktail, rain man, days of thunder, interview with the vampire.
then in 1996, he starred as a superspy ethan hunt in the very popular and blockbuster movie which went on to be a series, mission: impossible. that same year he also was seen in the lead role of the movie jerry maguire and won a golden globe for the same. in 1999, his supporting role in the movie magnolia again won him his second golden globe.
after repeated success in many films, tom cruise kept going on with release of two mission impossible movies, war of the worlds which was a super duper box office hit and many more.
net worth
tom cruise’s films have gained $7.3 million worldwide as of 2013. however, the net worth of the highest paid actor in hollywood is $270 million and he still gets paychecks from his previous movies.

you may also like 
the top 10 highest paid actors of all time

al pacino salary

how much money does jean-claude van damme make? (salary & net worth)

how much money does arnold schwarzenegger make? (net worth & biography)

how much money does jean-claude van damme make? (net worth)
posted in
action ,
celebs
tags:
highest paid actor ,
highest paid actor in hollywood ,
net worth ,
salary ,
thomas cruise mapother ,
tom cruise
«

判刑结果:

acting career of tom cruise started quite early but with a small role in the movie endless love 1981 however he got his big break as a supporting actor in the movie taps later that year in 1983 his movies risky business and all the right moves along with top gun in 1986 paved the path for tom cruise as an established actor and a superstar after this there was no looking back and tom cruise went to star in many supersuccessful movies like cocktail rain man days of thunder interview with the vampire
then in 1996 he starred as a superspy ethan hunt in the very popular and blockbuster movie which went on to be a series mission impossible that same year he also was seen in the lead role of the movie jerry maguire and won a golden globe for the same in 1999 his supporting role in the movie magnolia again won him his second golden globe
after repeated success in many films tom cruise kept going on with release of two mission impossible movies war of the worlds which was a super duper box office hit and many more
net worth
tom cruises films have gained 73 million worldwide as of 2013 however the net worth of the highest paid actor in hollywood is 270 million and he still gets paychecks from his previous movies

you may also like 
the top 10 highest paid actors of all time

al pacino salary

how much money does jeanclaude van damme make salary  net worth

how much money does arnold schwarzenegger make net worth  biography

how much money does jeanclaude van damme make net worth
posted in
action 
celebs
tags
highest paid actor 
highest paid actor in hollywood 
net worth 
salary 
thomas cruise mapother 
tom cruise

how much money does mike tyson make salary  net worth
how much money does jack black make salary  net worth

问题是如何保留句子的标点符号,但删除了非句子的特殊字符。

我想得到如下结果:

acting career of tom cruise started quite early but with a small role in the movie endless love (1981). however, he got his big break as a supporting actor in the movie taps later that year. in 1983, his movies risky business and all the right moves along with top gun in 1986 paved the path for tom cruise as an established actor and a superstar. after this there was no looking back and tom cruise went to star in many super-successful movies like cocktail, rain man, days of thunder, interview with the vampire.
then in 1996, he starred as a superspy ethan hunt in the very popular and blockbuster movie which went on to be a series, mission: impossible. that same year he also was seen in the lead role of the movie jerry maguire and won a golden globe for the same. in 1999, his supporting role in the movie magnolia again won him his second golden globe.
after repeated success in many films, tom cruise kept going on with release of two mission impossible movies, war of the worlds which was a super duper box office hit and many more.
net worth
tom cruise’s films have gained $7.3 million worldwide as of 2013. however, the net worth of the highest paid actor in hollywood is $270 million and he still gets paychecks from his previous movies.

1 个答案:

答案 0 :(得分:1)

我会先使用这个正则表达式将非句子与句子隔离开来:

(?<=\n|^)[\S]*\s*?[\S]*\s*?[\S]*\s*?[\S]*\s*?[\S]*\s*?[\S]*(?=\n|$)

然后,使用简单的替换函数从非句子中删除spacial character

演示:https://regex101.com/r/phrtfF/1