pandaiam 发表于 2018-08-03 12:43

正则表达式怎么用。。

现在有这个字符串
jakee and zz done.<p>zzz</p> <p style=\"text-align: center;\" align=\"justify\">==TUIGUANG===</p>\n<p align=\"justify\"><img style=\"width: auto;\" src=\"https://imag.xxxx.com/b931035c-5bf2-4553-9593-07480f74a5c6.png\" /></p> this should not dispeared <p>ALL MY ...</p> <p > See you</p> behan

现在用
regexp.MustCompile(`<p.*?TUIGUANG.*?</p>`)
匹配,愿意是想匹配到
<p style=\"text-align: center;\" align=\"justify\">==TUIGUANG===</p>结果是直接匹配到了
<p>zzz</p> <p style=\"text-align: center;\" align=\"justify\">==TUIGUANG===</p>有什么写法可以只匹配到最短的那段吗。。

我不知道别的正则是不是支持这种匹配,引用程序是用go写的,就先关注go的regexp了。

谢谢。


lxyscls 发表于 2018-08-08 10:51

回复 1# pandaiam
...

lxyscls 发表于 2018-08-08 10:51

本帖最后由 lxyscls 于 2018-08-08 10:53 编辑

回复 1# pandaiam
In : r = re.search('<p\ .*?TUIGUANG.*?</p>', 'jakee and zz done.<p>zzz</p> <p style=\"text-align: center;\" align=\"justify\">==TUIGUANG===</p>\n<p align=\"justify\"><img style=\"width: auto;\" src=\"https://imag.xxxx.com/b931035c-5bf2-4553-9593-07480f74a5c6.png\" /></p> this should not dispeared <p>ALL MY ...</p> <p > See you</p> behan')

In : r.group()
Out: '<p style="text-align: center;" align="justify">==TUIGUANG===</p>'

python


页: [1]
查看完整版本: 正则表达式怎么用。。