这是我的字符串
REGISTER sip:192.168.178.1 SIP/2.0
Call-ID: bla@192.168.178.60
CSeq: 1441 REGISTER
From: "620" <sip:620@192.168.178.20>;tag=bla
To: "620" <sip:620@192.168.178.20>
Via: SIP/2.0UDP 192.168.178.60:59488;branch=bla;rport
Max-Forwards: 70
User-Agent: bla
Contact: *
Expires: 0
Content-Length: 0
所以这个字符串有几个换行符。我的正则表达式是这种形式:
sipRequest = sipRequest.replaceFirst("(From: \")(.*)(\" <sip:)(.*)@(.*)>", "$1$2$3$4@" + sipServer + ">");
此正则表达式匹配,但不匹配以下一个:
sipRequest = sipRequest.replaceFirst("(^From: \")(.*)(\" <sip:)(.*)@(.*)>", "$1$2$3$4@" + sipServer + ">");
注意:唯一的区别是“From”之前的“^”符号。那么为什么这个表达式不匹配呢?它从一个新行开始,所以它应该匹配。
感谢帮助。