2013-12-20 36 views
0

我unablt使用下面的代碼來匹配以下字符串,我不知道什麼是對正則表達式無法匹配字符串

$regex = "/\\251/i"; 
if (preg_match($regex, $contents)) { 
    echo 'good it works'; 
} 

去的$內容如下

Shanghai Taipei Tokyo TorontoOxford is a registered trade mark of Oxford University Pressin the UK and in certain other countriesPublished in the United Statesby Oxford University Press Inc., New YorkRevised text \251 John Guy 2000

我已經試過了字符串編碼到沒有運氣

$contents = utf8_encode ($contents); 

這適用於我使用的所有在線工具,我是否錯過任何內容以瞭解爲什麼它在運行時不起作用?

+0

你想在字符串中匹配'\ 251'嗎? –

+1

確保您沒有'$ regex'和'$ regext'的拼寫錯誤。 – Rikesh

+0

是的,我在這個網站做了以下工作,但不是當ranhttp://www.phpliveregex.com/ – user3117904

回答

0

你應該嘗試:

preg_match('/(\xA9)/i', $text); 

或者:

preg_match('/(\251)/i', $text); 
0

在我試圖PERL檢查正則表達式是否正確與否。請發現其具有完美匹配\ 251

#!C:\Perl64\bin 
$regex = "Shanghai Taipei Tokyo TorontoOxford is a registered trade mark of Oxford University Pressin the UK and in certain other countriesPublished in the United Statesby Oxford University Press Inc., New YorkRevised text \251 John Guy 2000"; 
if ("$regex" =~ m/(\251)/) 
{ 
    print "Success scenario\n"; 
    print "$regex is matched \n"; 
} else { 
    print "$regex is not matched \n"; 
} 

這將輸出的正則表達式下面的Perl代碼 - >

Success scenario 
Shanghai Taipei Tokyo TorontoOxford is a registered trade mark of Oxford Univers 

,兩者均壓力機,加工英國和其他一些countriesPublished在美國Statesb ÿ牛津大學出版公司,新YorkRevised文\約翰·251蓋伊2000匹配

希望

這可以幫助你

臨屋

nks