How to get arguments from a string node.js. For example POST http://localhost:3000 --header={'Content-Type': 'application/json'} --body={user: 'hello'}
, how do I get the header
and body
?
CodePudding user response:
var src = "POST http://localhost:3000 --header={'Content-Type': 'application/json'} --body={user: 'hello'}"
var result = src.match(/[^{}]*(?=\})/gi); // Get all substrings between curly brace.
var header = result[0]
var body = result[1]