Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.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
如何使用regex惰性地匹配包含特定字符串的字符串?_Regex_Python 3.x - Fatal编程技术网

如何使用regex惰性地匹配包含特定字符串的字符串?

如何使用regex惰性地匹配包含特定字符串的字符串?,regex,python-3.x,Regex,Python 3.x,我想在python中使用正则表达式来匹配一个字符串,该正则表达式包含一个特定的字符串(惰性匹配),但还没有弄清楚如何进行匹配 例如,在下面的示例中,如何仅返回'some text some other text' 而不是整根绳子 #/垃圾桶/蟒蛇3 进口稀土 pattern=r'(]*>.*其他文本。*?' text='some text some other text' 打印(重新搜索(模式、文本、重新点播).groups(0)) 当我想要打印时,上面的代码会打印some text some

我想在python中使用正则表达式来匹配一个字符串,该正则表达式包含一个特定的字符串(惰性匹配),但还没有弄清楚如何进行匹配

例如,在下面的示例中,如何仅返回
'some text some other text'
而不是整根绳子

#/垃圾桶/蟒蛇3
进口稀土
pattern=r'(]*>.*其他文本。*?'
text='some text some other text'
打印(重新搜索(模式、文本、重新点播).groups(0))
当我想要打印时,上面的代码会打印
some text some other text

当然,所有这些都假设在
tag1

的位置可以有任何标记,结果证明,解决方案非常简单,下面是有效的正则表达式:


*(]*>.*其他一些文本。*?.*

使用xml解析器可能更好。谢谢你的建议,但是对于我的用例,它是不合适的。