I have the following string in JavaScript which is a basic oData batch request:
--batchfull
Content-Type: multipart/mixed; boundary=batchitems
--batchitems
Content-Type: application/http
Content-Transfer-Encoding: binary
MERGE /WcfDataService1.svc/Orders(1) HTTP/1.1
Content-Type: application/json;type=entry
{"OID":"2340324","PID":"234234"}
--batchitems
Content-Type: application/http
Content-Transfer-Encoding: binary
POST /WcfDataService1.svc/Users HTTP/1.1
Content-Type: application/json;type=entry
{"PID":"234234","Name":"User1"}
--batchitems--
--batchfull--
Each item which makes up the batch is as follows:
--batchitems
Content-Type: application/http
Content-Transfer-Encoding: binary
POST /WcfDataService1.svc/Users HTTP/1.1
Content-Type: application/json;type=entry
{"PID":"234234","Name":"User1"}
// new line here too
I am trying to write a regex to extract each of these batch items, but I can't get it working. So far I have:
/--batchitems$.*?(?=--batchitems)/ig
But, it does not work.
1) I tried building it up so at first I had /--batchitems$/ig. Without the dollar, it worked, with it, it did not work (nothing was matched).
Any ideas how to get this working?
You may use [\\s\\S]*?
intstead of .*
, since js won't support DOTALL modifier s
.
/--batchitems\n([\s\S]*?)(?=--batchitems)/ig
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.