![](/img/trans.png)
[英]Regex with PHP preg_replace() need to find the nearest name in string
[英]PHP Find and Preg_replace a regex in a string
我希望正则表达式只用tweet id替换。 我试过下面的正则表达式,但不起作用。
$string = "The meeting, which was also attended by Chief Bisi Akande, held at the Abuja House in London, a tweet from the presidency revealed.
[twt]https://twitter.com/NGRPresident/status/829704039952740352[/twt]
[twt]https://mobile.twitter.com/NGRPresident/status/829713387001114625[/twt]
President Buhari has been away from Nigeria since January when he departed for a 10-day medical vacation.";
$regex = '/\[twt\]\/https?://twitter\.com/(?:\#!/)?(\w+)/status(es)?/(\d+)[\/twt\]/';
$string = preg_replace("$regex", '$3', $string);
echo $string;'
我想要结果输出;
这次会议由总统府发布的推文在伦敦阿布贾众议院举行。
829704039952740352
829713387001114625
布哈里总统自1月份离开尼日利亚后,离开了为期10天的医疗假期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.