从内容帖子中删除所选文本而不删除帖子本身(Wordpress)

时间:2017-09-03 14:53:31

标签: mysql regex

我刚学会了如何根据标题中的特定关键字删除帖子,以便用MySQL执行。现在我正在尝试学习如何执行类似的脚本来搜索帖子内容并删除以下HTML代码:

<input id="website_url" class="c7" type="text" value="this text changes" />

值本身会发生变化,但只要脚本删除包含的所有内容,直到/&gt;它会起作用。

这是我之前关于帖子标题的用法

DELETE FROM wp_posts WHERE post_title REGEXP '\\1970-01-01 01:00:00'

我知道上面没有相关性,但我输入的关于我想要删除的内容是我为之奋斗的地方

1 个答案:

答案 0 :(得分:0)

我建议:

select * from toy;
with key(string1) as (select '<input id="website_url" class="c7" type="text" value="')
update toy set html =
(   select
        substr(html,0,instr(html, (select string1 from key)))
        ||
        substr(substr(html,4+instr(html, (select string1 from key))),
               instr(substr(html,instr(html, (select string1 from key))), '" />'  )
              )
)
where html like '%'||(select string1 from key)||'%';

基本上

  • 仅在搜索到的html的固定部分发生时更新,
    where html like '%'||(select string1 from key)||'%';
  • 通过连接之前的字符串和之后的字符串进行更新,
    update ... set html = ...||...
  • 避免使用带有CTE的长重复字符串,
    with key(string1) as (select '...') - &gt; (select string1 from key)
  • 字符串上的一些sqlite魔法,instr(...)substr(...)
  • 稍微丑陋,硬编码应该是第二个字符串的长度,
    4+