2013-12-20 76 views
2

我需要一個正則表達式匹配:正則表達式匹配CDATA節

開始與

<![CDATA[ 

包含:

wildcard

(其中很多,包括但不限於<>"./和多行字母和數字)。用它來清除一個非常大的ajax xml文件的lipsum

]]> 

林:

和結束。

香港專業教育學院環顧四周,無法弄清楚如何感嘆號

我想產生一個與http://www.jslab.dk/tools.regex.php,這給了匹配:

/^(?:<\!\[CDATA\[)\]\]>$/m 

這不會在測試使用編輯器IM匹配或。

回答

1

與此正則表達式嘗試

<!\[CDATA\[.*?\]\]> 

OR

<!\[CDATA\[((?:[^]]|\](?!\]>))*)\]\]> 

Please See Demo Here

+0

雙雙創下。第一個很容易。我想你不會逃避的!根本就是括號。 – Thatoneguy7

0

請找到下面的Perl代碼相匹配,其期望正則表達式。

PERL代碼: -

#!C:\Perl64\bin 
$regex = "<![CDATA[ Shanghai Taipei Tokyo !!!!?<,;'[*()&^%$#@! CDATA TorontoOxford ] is a registered [trade mark of Oxford University Pressin the UK New YorkRevised text ?? John Guy 2000 ]]>"; 
if ("$regex" =~ m/^(<!\[CDATA\[)/ && "$regex" =~ m/(\]\]>)$/) 
{ 
    print "Success scenario matched \n"; 
    print "$regex is matched \n"; 
} else { 
    print "Failure scenario matched \n"; 
    print "$regex is not matched \n"; 
} 

輸出: -

Success scenario matched 
<![CDATA[ Shanghai Taipei Tokyo !!!!?<,;'[*()&^%-1! CDATA TorontoOxford ] is a r 
egistered [trade mark of Oxford University Pressin the UK New YorkRevised text ? 
? John Guy 2000 ]]> is matched 

希望這可以幫助你

感謝

+0

我很欣賞這種努力,但我無法使用該正則表達式,而且我也不使用perl。也許它會幫助其他人找到這個SO。 – Thatoneguy7

+0

Thanks @ Thatoneguy7理念在正則表達式中,圓括號()有助於匹配其中提到的精確regrex。因此,嘗試在lang中查找相同的選項。您正在使用。可能它可能在那裏有一些不同於()的選項。 – Jigar