正则表达式使用向前或向后

时间:2018-08-29 07:48:23

标签: regex lookahead

我正在尝试解决使用正则表达式匹配部分字符串的问题。

例如,如果我的

bigString = 'I am going to school. Which one, said one of the friend. Well, I dont know but it is owned by Beats Ltd., and I kind of like it and our principal K.L.Doubies is extremely good. I cant imagine going to any other school.'

如果我要提取一部分以点开头但在至少2个字符后不包含点且包含“主要”字词的字符串。简而言之,我需要一个完整的句子。因此,在我的bigString中,我想匹配-''. Well, I dont know but it is owned by Beats Ltd., and I kind of like it and our principal K.L.Doubies is extremely good.''

这是我的尝试:

r'\.((?!\w\w+\.).)*principal.*?\w\w+\.'

(?!\w\w+\.)中,我很想使用异常来忽略Ltd. Co. Dr.之类的词。

0 个答案:

没有答案