首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

怎么用正规表达式查找不以某些字符结尾的单词

2012-02-21 
如何用正规表达式查找不以某些字符结尾的单词例如现在有一篇英文文章,如何找出所有不以ly结尾的单词呢?[解

如何用正规表达式查找不以某些字符结尾的单词
例如现在有一篇英文文章,如何找出所有不以ly结尾的单词呢?

[解决办法]
我怀疑是找以ly结尾的单词,因为这样比较少一点。不管了,我两种都写一下吧:

Python code
import retxt = '''Dementia is a loss of intellectual ability that affects memory, learning,attention, thinking and language skills. People with dementia may forgetfamily members or not know what day it is. Sometimes they become angry or sad,hear voices, or see things that are not there.The team found that dementia was the largest cause of disability in the elderlyin areas other than rural India and Venezuela. Other major causes were stroke,loss of use of arms or legs, arthritis, depression, eyesight problems andgastrointestinal problems.The study says the elderly are nine percent of the total population of low andmiddle income countries today. But their numbers are growing quickly. They areexpected to reach twenty percent of the total population by the middle of thecentury.It found that in almost half the countries, children who were not breastfeedwere much more likely to have a disability than those who were. The same wastrue of those who did not receive vitamin A supplements and those who wereunderweight.Children who did not take part in early learning activities or attend schoolwere also more likely to be disabled than those who did.'''regEndWith_ly = re.compile(r'[a-zA-Z]+?ly', re.I | re.S)print regEndWith_ly.findall(txt)regNotEndWith_ly = re.compile(r'\b[a-zA-Z]+?(?<!ly)\b', re.I | re.S)print regNotEndWith_ly.findall(txt) 

热点排行