Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中获得多个正则表达式匹配?_Python_Regex - Fatal编程技术网

如何在python中获得多个正则表达式匹配?

如何在python中获得多个正则表达式匹配?,python,regex,Python,Regex,我有以下案文: <div class="additional-details"> <div class="mark-container"> <input type="checkbox" id="comp-80174649" value="80174649" data-heading-code="2550"/> <label for="comp-80174649">???</label> <

我有以下案文:

 <div class="additional-details">
  <div class="mark-container">
   <input type="checkbox" id="comp-80174649" value="80174649"
          data-heading-code="2550"/>
   <label for="comp-80174649">???</label>
   <a href="#" class="compare-link" id="compare-link-1"
      data-compare="/80174649/2550/"
      data-drop-down-id="compare-content-1"
      data-drop-down-content-id="compare-content"
      data-drop-down-class="drop-down-compare"
      etc...
      data-compare="/8131239/2550/"

???

re.findall
可用于查找列表中的所有匹配项

>>> import re
>>> s = '<div cla'  # whole string here
>>> result = re.findall('data-compare="([\d/]+)"', s)
>>> print result
['/80174649/2550/', '/8131239/2550/']
>>重新导入

>>>你的具体问题是什么?i、 e.是否希望将
/
之间的数字提取为一个列表?好吧,让我们忘记数字,假设它可以是任何数字(即使现在有数字)。我想匹配data compare=”和“@roippi谁说它是XML的?它基本上是html。我知道我可以使用一些html解析器,但我想在这种情况下使用正则表达式。太棒了!谢谢所以没有必要逃跑?([\d/]+)是什么意思?不,它们不需要转义。您可以找到需要转义的特殊字符列表。我编辑了答案,并解释了我使用的正则表达式字符串。