Regex 正则表达式需要忽略目录更新(..)
嘿,伙计们,我的正则表达式出错了,需要修复 当我撞到一个。。在url中,我得到了一个匹配项,我不应该这样做 这是正则表达式Regex 正则表达式需要忽略目录更新(..),regex,Regex,嘿,伙计们,我的正则表达式出错了,需要修复 当我撞到一个。。在url中,我得到了一个匹配项,我不应该这样做 这是正则表达式 ~\b(?::url|:\surl)\s*\(\s*(["\']?+)\K(?:/(?!/)|(?=[\s>]|\1))~i 我想应该是的 ~\b(?::url|:\surl)\s*\(\s*(["\']?+)\K(?:/(?!/|..)|(?=[\s>]|\1))~i 但这似乎不起作用 它应该匹配的东西 background:url('/foo.jpg')
~\b(?::url|:\surl)\s*\(\s*(["\']?+)\K(?:/(?!/)|(?=[\s>]|\1))~i
我想应该是的
~\b(?::url|:\surl)\s*\(\s*(["\']?+)\K(?:/(?!/|..)|(?=[\s>]|\1))~i
但这似乎不起作用
它应该匹配的东西
background:url('/foo.jpg') repeat-y top center;
background:url("/foo.jpg") repeat-y top center;
background:url(/foo.jpg) repeat-y top center;
background:url('foo.jpg') repeat-y top center;
background:url("foo.jpg") repeat-y top center;
background:url(foo.jpg) repeat-y top center;
background: url('/foo.jpg') repeat-y top center;
background: url("/foo.jpg") repeat-y top center;
background: url(/foo.jpg) repeat-y top center;
不应该匹配,但应该匹配
background:url('../foo.jpg') repeat-y top center;
background:url("../foo.jpg") repeat-y top center;
background:url(../foo.jpg) repeat-y top center;
background: url('../foo.jpg') repeat-y top center;
background: url("../foo.jpg") repeat-y top center;
background: url(../foo.jpg) repeat-y top center;
并使用?!/| \.\。看来还是相配的想明白了,我的排斥需要在我回头看的后面
~\b(?::url|:\surl)\s*\(\s*(["\']?+)(?:(?!\.\./))\K(?:/(?!/)|(?=[\s>]|\1))~i
您可以添加它匹配但不应该添加的字符串吗?需要转义。->\。,因为它是正则表达式中的一个特殊字符。