2016-07-08 74 views
-4

我嘗試了一些正則表達式模式,但仍找不到一些解決方案。如何從字符串中找到「<< >>」字樣

我想從以下字符串中獲得<< >>單詞。

$string = "Yes! Bariatric surgery is covered under your plan. Click <<COMPANY>> here to contact a local surgeon and ask them to confirm your insurance benefits for free. See our <<INSURANCE>> page for coverage criteria or scroll down this page to learn more."; 
$dash = substr($string,strpos($string,"<<"),strpos($string,">>")); 

如果有人知道請幫助我。

謝謝。

+3

OK的話,這裏是你的代碼,什麼是它的問題? – Kasramvd

+0

請用您的代碼更新您的問題並解釋輸出有什麼問題? – Kasramvd

+0

我找到了我的解決方案... – user3374268

回答

1

這個正則表達式匹配<<>>

\<{2}([^\>]+)\>{2} 

https://regex101.com/r/eX4xI4/1

preg_match_all("/\<{2}([^\>]+)\>{2}/", $string, $matches); 
print_r($matches); 

https://eval.in/602428

+0

謝謝巴迪它的工作...... – user3374268

+0

沒有汗水':)'很高興我能幫到 –

+0

如果它有效,你應該接受答案。 '<' and '>'不需要轉義; '​​] +)> {2}'。 – chris85

相關問題