且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Python 中使用正则表达式排除特定字符串?

更新时间:2022-11-14 19:02:23

你可以试试这个正则表达式来匹配所有没有字符串 you 的行? 最后,

You could try this regex to match all the lines which doesn't have the string you with ? at the last,

^(?!.*you).*\?$

说明:

在这个正则表达式中使用了负前瞻.它实际上意味着什么,它检查包含字符串 you 的行.它匹配除包含字符串 you 的行之外的所有行.

A negative lookahead is used in this regex. What it does actually means, it checks for the lines which contains a string you. It matches all the lines except the line containing the string you.

演示