为什么这个正则表达式断言不匹配? [英] Why this regex assertion doesn't match?
问题描述
我正在尝试在 html 标签之间预存内容,我正在尝试这个简单的断言模式,但我不明白为什么它不匹配这个字符串.
I'm trying to just preg content between html tags, I'm trying this simple assertion pattern and I don't understand why it doesn't match this string.
<a href=http://url.com title="link">this is a ling</a>
(?<=<a.*>)([ w]*)(?=<.*/a>)
推荐答案
Lookbehinds on debuggex(PCRE、Javascript 和 Python)不能是可变宽度的,这意味着您可以使用 (?<=<a>)
具有固定宽度(3 个字符)但长度不能变化 (?<=<a.*>)
(可以有 3 个字符,或 4 个字符),或 5 等).
Lookbehinds on debuggex (PCRE, Javascript and Python) cannot be of variable width, meaning that you can use (?<=<a>)
which has a fixed width (3 characters) but not something that can vary in length (?<=<a.*>)
(can have 3 characters, or 4, or 5, etc).
正则表达式根本无效,但 debuggex 告诉您没有匹配项.
The regex simply is not valid but debuggex tells you that there is no match.
这篇关于为什么这个正则表达式断言不匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!