[英]regular expression, not include characters
I have a pattern that looks like this: 我有一个看起来像这样的模式:
pattern = '.*class=(.*)'
and it gives me the result something like this: 它给我的结果是这样的:
my_class=Hello
your_class=Hi
fclass=FHello
class=That's What I need
Basically I want to say that I need to return a string that contains class
only, and not some fclass my_class
and so on 基本上,我想说的是,我需要返回一个包含字符串
class
而已,而不是一些fclass my_class
等
If you're running the regex on individual lines, you can use the ^
symbol to target the beginning of a regex: 如果要在单独的行上运行正则表达式,则可以使用
^
符号来定位正则表达式的开头:
pattern = r'^class=(.*)'
If not, word boundaries might be helpful: 如果没有,单词边界可能会有所帮助:
pattern = r'\bclass=(.*)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.