Replacing all matches except if surrounded by or only if surrounded by(替换所有匹配项,但被包围或仅当被包围时除外)
本文介绍了替换所有匹配项,但被包围或仅当被包围时除外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给定文本字符串(减价文档),我需要实现以下两个选项之一:
替换整个文档中特定表达式(
(W)(theWord)(W)
)的所有匹配项除标记图像语法
内的匹配项。替换特定表达式(
{{([^}}]+)}}[[[^]]]+]]
)仅的所有匹配项,即:![Blah {{theWord}}[[1234]] blah](url)
。
这两个表达式当前都匹配所有内容,无论是否在标记图像语法中,而且我已经尝试了我能想到的所有内容。
Here is an example of the first option
And here is an example of the second option
我们非常感谢您提供的任何帮助和/或线索。
提前感谢!
推荐答案
嗯,我稍微修改了一下第一个表达式,因为我认为有一些额外的捕获组,然后通过添加提前查找技巧来创建它们:
-第一个(Live demo):
(vitae)(?![^[]*]s*()
-第二个(Live demo):
{{([^}}]+)}}[[[^]]]+]](?=[^[]*]s*()
前视部件说明:
(?! # Starting a negative lookahead
[^[]*] # Everything that's between brackets
s* # Any whitespace
( # Check if it's followed by an opening parentheses
) # End of lookahead which confirms the whole expression doesn't match between brackets
(?=
表示积极向前看
这篇关于替换所有匹配项,但被包围或仅当被包围时除外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:替换所有匹配项,但被包围或仅当被包围时除外


猜你喜欢
- PHP - if 语句中的倒序 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01