正则表达不好\ g逃脱

时间:2018-05-22 01:01:47

标签: regex python-3.x

我有这个Python3正则表达式:

i = "some string wow https://www.amazon.ca/product-product-name"
print(re.match(r'\^https:\/\/www.amazon.[\b"com","ca"](.*)\g', i))

我收到此错误:

sre_constants.error: bad escape \g at position 41

代码应与https://www.amazon.ca/product-product-name匹配。

1 个答案:

答案 0 :(得分:2)

这里:

i = "some string wow https://www.amazon.ca/product-product-name"
print(re.findall(r'https://www\.amazon\.(?:com|ca)/(?:[^\s]+)', i))

打印:

['https://www.amazon.ca/product-product-name']

Link to interactive demo