]*{clickurl-6ren">
gpt4 book ai didi

用于匹配包含非 anchor 标记的字段的 mysql regexp 以及包含模式的 href 属性

转载 作者:太空宇宙 更新时间:2023-11-03 12:13:17 25 4
gpt4 key购买 nike

我正在尝试从数据库中查找其字段具有非 anchor 标记且其 href 属性以 {clickurl} 字符串开头的所有行。例如这个 -

<link foo="bar" href="{clickurl}http://wwww.google.com" ...

或者这个(因为它有一个符合条件的非 anchor 标签)- http://wwww.google.com"... http://wwww.google.com"...

但不是这个(因为它是一个 anchor 标签)- http://wwww.google.com"...

到目前为止我做了什么

使用以下正则表达式,我能够获取链接标记具有以 {clickurl} 开头的 href 属性的所有记录 -

SELECT bannerid FROM ox_banners WHERE htmltemplate REGEXP "<link[^>]*href\s*=\s*[\"'][^>]*{clickurl}(.*)[\"']"

但是,由于我不仅需要搜索链接标签,还需要搜索任何其他标签(不包括 anchor 标签),我将正则表达式修改为 -

SELECT bannerid FROM ox_banners WHERE htmltemplate REGEXP "<[!a][^>]*href\s*=\s*[\"'][^>]*{clickurl}(.*)[\"']"

但这也会返回 anchor 标记包含此模式的行。

更新

对于来自 zx81 的输入,我现在使用这个表达式 <[^a][^>]*href[[:space:]]*=[[:space:]]*[\"'][^>]*{clickurl}(.*)[\"']并且在正常情况下只有非 anchor 标记匹配,但在以下情况下,当 href 属性位于 PHP 标记内 echo 语句内的标记上时,它也会匹配(不需要),因为实际上它是一个 anchor 标记上的 href -

<?php

$GLOBALS['test'] = '{clickurl}tel://test';

echo '<a href="{clickurl}test">Test</a>';

?>

我仍在寻找此修复程序。

最佳答案

试试这个:

SELECT bannerid FROM ox_banners WHERE htmltemplate REGEXP ".*<[^a][^>]*href=\"\\{clickurl\\}.*";


Options: Case insensitive; Regex syntax only
Match any single character that is NOT a line break character (line feed) «.*»
Between zero and unlimited times, as few or as many times as needed to find the longest match in combination with the other quantifiers or alternatives «*»
Match the character “<” literally «<»
Match any single character that is NOT present in the list below and that is NOT a line break character (line feed) «[^a]»
The literal character “a” (case insensitive) «a»
Match any single character that is NOT present in the list below and that is NOT a line break character (line feed) «[^>]*»
Between zero and unlimited times, as few or as many times as needed to find the longest match in combination with the other quantifiers or alternatives «*»
The literal character “>” «>»
Match the character string “href="” literally (case insensitive) «href="»
Match the character “{” literally «\{»
Match the character string “clickurl” literally (case insensitive) «clickurl»
Match the character “}” literally «\}»
Match any single character that is NOT a line break character (line feed) «.*»
Between zero and unlimited times, as few or as many times as needed to find the longest match in combination with the other quantifiers or alternatives «*»

关于用于匹配包含非 anchor 标记的字段的 mysql regexp 以及包含模式的 href 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23338868/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com