Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个看起来像这样的模式:
pattern = '.*class=(.*)'
它给了我这样的结果:
my_class=Hello your_class=Hi fclass=FHello class=That's What I need
基本上我想说我需要返回一个class只包含的字符串,而不是一些fclass my_class等等
class
fclass my_class
如果您在单独的行上运行正则表达式,则可以使用该^符号来定位正则表达式的开头:
^
pattern = r'^class=(.*)'
如果没有,单词边界可能会有所帮助:
pattern = r'\bclass=(.*)'