[英]Explode the word from sentence regardless of any special characters using PHP regular expression
[英]Remove All the occurrence of Word from Sentence Using Regular Expression
您好,我想從下面的句子中刪除單詞。 我怎么能用正則表達式做到這一點
ABC (+£768.00):Yes, 1 Top Access with 2 Socket (+£28.00):Yes , 2 USB and 2 RJ45 (Black)
我想刪除所有以“(+”開頭並以“):”結尾的單詞。
例如:我想從上面的行中刪除 " (+£768.00): " 和 " (+£28.00): "。
請幫我解決一下這個。
謝謝你
只需按照模式要求使用以下正則表達式:
\(\+.*?\)\:
匹配(+
原樣由 escaping 后跟 0 個或多個以 結尾的字符的非貪婪匹配):
再次需要轉義。 使用preg_replace
將匹配項替換為空字符串。
<?php
echo preg_replace('/\(\+.*?\)\:/', '', 'ABC (+£768.00):Yes, 1 Top Access with 2 Socket (+£28.00):Yes , 2 USB and 2 RJ45 (Black)');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.