开发者

preg_replace with php

开发者 https://www.devze.com 2023-03-26 00:48 出处:网络
I would like to replace \":\" with \"\\xEF\\xBC\\x9A\" however, I do not want to do this for : that follows \"http\", \"https\", and string with the format of @[{numbers}:{numbers}:{some text}].

I would like to replace ":" with "\xEF\xBC\x9A" however, I do not want to do this for : that follows "http", "https", and string with the format of @[{numbers}:{numbers}:{some text}]. What I have doesn't really work as (?<!@\[\d) does not check what's after it. My current implementation only work for something like @[1:2:text]. Thanks!

$stri开发者_JAVA百科ng=preg_replace('#(?<!https)(?<!http)(?<!@\[\d)(?<!@\[\d:\d):#', "\xEF\xBC\x9A", $string);


Try this:

preg_replace('/(@\[\d+:\d+:[^]]*]|https?:)|:/e', '"$1"?"$1":"\xEF\xBC\x9A"', $string);


Try this regex:

(?<!@\[(?::?[\d]{0,5}){1,2})(?<!https?):

It should match the first and second instances of ':' here.

: test: http: @[1:2:text]

Usage Sample:

$string = preg_replace('/(?<!@\[(?::?[\d]{0,5}){1,2})(?<!https?):/', '\xEF\xBC\x9A', $string);
0

精彩评论

暂无评论...
验证码 换一张
取 消