正则表达式和preg_replace:如何在URL中多次匹配同一模式

问题描述

我想使用REGEX以两种不同的方式定位CITE标记,具体取决于它是否在URL中:

  • 如果标签位于URL中,则以www或http开头的标签都可以删除;
  • 如果该标签不在URL中,请保持完整标签

这是我要操作的字符串:

www.os<cite>map</cite>s.ordnancesurvey.co.uk/os<cite>map</cite>s/
and the normal text <cite>map</cite> here and again <cite>map</cite> here
http://os<cite>map</cite>s.ordnancesurvey.co.uk/os<cite>map</cite>s/
and the normal text <cite>map</cite> here and again <cite>map</cite> here

我一直在使用这个表达式:

$this_record = preg_replace('/((www.)|(https?:\/\/))([^\s]*?)(<cite>([^\s]*?)<\/cite>)([^\s]*)/','$2$3$4$6$7',$this_record);

这有效,但仅适用于第一组标记并导致:

www.osmaps.ordnancesurvey.co.uk/os<cite>map</cite>s/
and the normal text <cite>map</cite> here and again <cite>map</cite> here
http://osmaps.ordnancesurvey.co.uk/os<cite>map</cite>s/
and the normal text <cite>map</cite> here and again <cite>map</cite> here

URL中仅删除第一组标签。我该如何删除后续的?

非常感谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...