我想删除HTML文件中的所有http:
和https:
,但不包括placeholder="http:
和placeholder="https:
。我尝试了以下示例,但每个http:和https:都将被删除:
/(?!placeholder=")(http:|https:)/
您需要用lookbehind替换前瞻。此外,您可以将交替减少到仅仅https?:
模式,其中s?
表示1或0 s
:
'/(?<!placeholder=")https?:/'
^ ^^
如果要确保placeholder
匹配为整个单词,请添加单词边界:
'/(?<!\bplaceholder=")https?:/'
^^
如果在placeholder
之前必须有空格,请将\b
替换为\s
。
细节
(?<!\bplaceholder=")
- 一个字符串内的一个位置,紧接着一个完整的单词placeholder
然后="
http
- 一个http
子串s?
- 可选的s
:
- 一个冒号。