[英]Negative look ahead not working as expected
我有一個奇怪的情況,積極的前瞻按預期工作,但消極的前瞻卻沒有。 請看下面的代碼:
<?php
$tweet = "RT @Startup_Collab: @RiseOfRest is headed to OMA & LNK to #showcase our emerging #startup ecosystem. Learn more! https://example.net #Riseof…";
$patterns=array(
'/#\w+(?=…$)/',
);
$tweet = preg_replace_callback($patterns,function($m)
{
switch($m[0][0])
{
case "#":
return strtoupper($m[0]);
break;
}
},$tweet);
echo $tweet;
我想匹配任何沒有跟…$
和大寫的主題標簽(實際上它將用href
解析出來,但為了簡單起見,現在只是大寫)。
這些是帶有相應輸出的正則表達式:
'/#\\w+(?=…$)/'
/#\\w+(?=...$)/ '/#\\w+(?=…$)/'
匹配任何以…$
結尾的主題標簽並將其大寫,按預期工作:
RT @Startup_Collab: @RiseOfRest is headed to OMA & LNK to #showcase our emerging #startup ecosystem. Learn more! https://example.net #RISEOF…
'/#\\w+(?!…$)/'
/#\\w+(?!...$)/ '/#\\w+(?!…$)/'
匹配任何不以…$
結尾的主題標簽並且大寫它,不起作用,所有主題標簽都是大寫的:
RT @Startup_Collab: @RiseOfRest is headed to OMA & LNK to #SHOWCASE our emerging #STARTUP ecosystem. Learn more! https://example.net #RISEOf…
非常感謝您的任何幫助、建議、想法和耐心。
- 天使
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.