我搜索了一百萬個類似的問題,但沒有找到這個特定場景的答案。PHP如何preg_match大於/小於文本中間的符號?
問題:
<?php
$text = "some words | other words";
$text2 = "some words > other words";
$text3 = "some words < other words";
print preg_match("/\s+\|\t/", $text); //this works, will print 'true'
print preg_match("/\s+(<|>|\|)\t/", $text2); //never true for $text2 or $text3
print preg_match("/\s+[<\|>]\t/", $text3); //never true for $text2 or $text3
?>
我需要的東西,這將是真正的所有3種方案。
我試過後視,向前看,我無法弄清楚那裏有什麼工作。這些對我來說還是有些陌生的。
'<', '>'或'|'後面的空格不是簡單的'tab',否則它應該打印'1'。 – revo
'\ s + [\ | \ <|\>] \ s +'會匹配所有場景。這是你在找什麼? – Technomad
是否需要空格?我認爲'\ h * [<> |] \ h +'會起作用,如果需要空格,請將'*'改爲'+'。 – chris85