[英]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}]. 我想将“:”替换为“ \\ xEF \\ xBC \\ x9A”,但我不想这样做:它遵循“ http”,“ https”和@@ {numbers}格式的字符串: {numbers:{some text}]。 What I have doesn't really work as
(?<!@\\[\\d)
does not check what's after it. 我所拥有的并没有真正起作用,因为
(?<!@\\[\\d)
不会检查它后面的内容。 My current implementation only work for something like @[1:2:text]
. 我当前的实现仅适用于
@[1:2:text]
。 Thanks! 谢谢!
$string=preg_replace('#(?<!https)(?<!http)(?<!@\[\d)(?<!@\[\d:\d):#', "\xEF\xBC\x9A", $string);
尝试这个:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.