Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.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,我有一根绳子 状态:ActiveCode:C1654Shop使用pythonre模块 您没有解释要遵循的模式,因此我可以给出一个适用于上述字符串的示例: import re results = [] reg = '.*?>.*?: (.+?)<br' my_str = '<b>Status : Active<br>Code : C1654<br><br>Shop <a class="top"<b>Shop A</

我有一根绳子

状态:ActiveCode:C1654Shop使用pythonre模块 您没有解释要遵循的模式,因此我可以给出一个适用于上述字符串的示例:

import re
results = []
reg = '.*?>.*?: (.+?)<br'
my_str = '<b>Status : Active<br>Code : C1654<br><br>Shop <a class="top"<b>Shop A</b></a></b>'
results+=re.findall(reg,my_str)
reg2 = '<a.*?<b>(.*?)</b>'
results += re.findall(reg2,my_str)
print result
>>>['Active', 'C1654', 'Shop A']

我希望我帮了忙,谢谢@Rptk99@heroku没问题!,很乐意帮忙