preg_replace with php
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);
精彩评论