In Node.js, I would like to extract multiple strings from a given string. The string to search from looks like this:
Mon May 17 10:17:44 2021 SEND MESSAGE TO NETWORK (10.0.158.24:5060 [UDP]) (BUFF LEN = 308)
----------------------utf8-----------------------
SIP/2.0 100 Trying
To: "+3212345678" <sip:[email protected];user=phone>
From: "+32456123456" <sip:[email protected];user=phone>;tag=1c506737759
Call-ID: [email protected]
CSeq: 1 INVITE
Via: SIP/2.0/UDP 10.0.158.24:5060;branch=z9hG4bKac551823835
Content-Length: 0
-------------------------------------------------
Mon May 17 10:17:44 2021 11f7 [CCall::checkAuthentication] INVITE
Mon May 17 10:17:44 2021 [DBG: CResponse::freeAttributes] Ends
Mon May 17 10:17:44 2021 6367C [CMessage::send] sip_sendMessage (10.0.158.24:5060)
Mon May 17 10:17:44 2021 SEND MESSAGE TO NETWORK (10.0.158.24:5060 [UDP]) (BUFF LEN = 496)
----------------------utf8-----------------------
SIP/2.0 480 Temporarily not available
Allow: INVITE, ACK, CANCEL, BYE, PRACK, NOTIFY, REFER, SUBSCRIBE, OPTIONS, UPDATE
User-Agent: OmniPCX Enterprise R12.4 m5.204.2.b
To: "+3212345678" <sip:[email protected];user=phone>;tag=fa4096f6eb58184a573b7fcb86a7adff
From: "+32456123456" <sip:[email protected];user=phone>;tag=1c506737759
Call-ID: [email protected]
CSeq: 1 INVITE
Via: SIP/2.0/UDP 10.0.158.24:5060;branch=z9hG4bKac551823835
Content-Length: 0
-------------------------------------------------
1621239464 -> Mon May 17 10:17:44 2021 6367C [CMessage::onSendSuccess]
Mon May 17 10:17:44 2021 2107 [CTransaction::onSendSuccess] CMessage 6367C send Success
Mon May 17 10:17:44 2021 15cd [CDialog::onSendSuccess]
I want to extract everything between '----------------------utf8-----------------------' and '-------------------------------------------------'
I tried following:
let matches = givenString.match(/-{22}utf8-{23}(.*?)-{49}/g).map((val) => {
return val.replace(/-{22}utf8-{23}/g, '')
})
console.log(matches)
But the result is 'TypeError: Cannot read property 'map' of null'
I also tried to without counting the '-' characters
let matches = givenString.match(/----------------------utf8-----------------------(.*?)-------------------------------------------------/g)
But same result ('TypeError: Cannot read property 'map' of null')
sflag at the end, single line. With it.matches new line characters.givenString?