2013-08-16 169 views
1

正如我從幾個小時嘗試。以下是字符串。帶正則表達式的Preg_match模式

Contact: <sip:[email protected]:54163> 
To: "915454454544"<sip:[email protected]> 
From: "6185347017"<sip:[email protected]>;tag=8237b810 
Call-ID: OTNhYzMxZDFmOThmMGI1ZmIxNmE3OGM2MGZkOTFkZTc. 
CSeq: 2 INVITE 
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO 
Content-Type: application/sdp 
Proxy-Authorization: Digest  username="6185347017",realm="103.24.124.2",nonce="5f69d948-0639-11e3-8d11-238fc92f6fd0",uri="s  ip:[email protected]",response="39a1d1688114ec06d5ccd49bba1b4883",cnonce="3c76312b0377 9cdf9c9aa4d3f2a1962a",nc=00000001,qop=auth,algorithm=MD5 
User-Agent: eyeBeam release 1102q stamp 51814 
Content-Length: 315 

我想To:價值和From:值和底部content-Length,我們需要這些值。

+1

你能告訴我們你的進展如何?你已經試過了什麼樣的正則表達式? –

+1

這很容易做到。你嘗試過什麼嗎? –

回答

0
To\:\s(.*)|From\:\s(.*)|Content\-Length\:\s(.\*) 

您將$ 1 $ 2 $ 3

1

去或來源:(To|From): ["0-9<:@.>;a-zA-Z:=]+
要獲得內容Lengh:Content-(l|L)ength: \d+

0

這裏有一個諾特爾方式使用正做了你的數據前瞻:

(?=To|From)\w+:\s"(\d+)"|Content-Length:\s(\d+) 

$1將包含您

$2將包含的Content-Length

,您可以嘗試HERE