javascript - Parse string regex for known keys but leave separator -
ok, nail little bit of snag trying create regex.
essentially, want string like:
error=some=new item user=max datefrom=2013-01-15t05:00:00.000z dateto=2013-01-16t05:00:00.000z
to parsed read
error=some=new item user=max datefrom=2013-01-15t05:00:00.000z ateto=2013-01-16t05:00:00.000z
so want pull known keywords, , ignore other strings have =.
my current regex looks this:
(error|user|datefrom|dateto|timefrom|timeto|hang)\=[\w\s\f\-\:]+(?![(error|user|datefrom|dateto|timefrom|timeto|hang)\=])
so i'm using known keywords used dynamically can list them beingness know.
how write include requirement?
you utilize replace so:
var input = "error=some=new item user=max datefrom=2013-01-15t05:00:00.000z dateto=2013-01-16t05:00:00.000z"; var result = input.replace(/\s*\b((?:error|user|datefrom|dateto|timefrom|timeto|hang)=)/g, "\n$1"); result = result.replace(/^\r?\n/, ""); // remove first line
result:
error=some=new item user=max datefrom=2013-01-15t05:00:00.000z dateto=2013-01-16t05:00:00.000z
javascript regex key-value
No comments:
Post a Comment