Skip to content
Advertisement

Retrieve the value of each custom markup

How to get each value after the “=” with the shortest script?

DATEADDED=20210301 20:21:02 IDENT=* IP=88.164.x.x REASON=aaa bbb ccc… NOTE=xxx xxx x x x x…

Put everything in an array

Example:

Result response of array : ['20210301 20:21:02', '*', '8.164.x.x', 'aaa bbb ccc...', 'xxx xxx x x x x...']

Advertisement

Answer

finally I was inspired by another code that I had for a long time in a source :

let test = "DATEADDED=20210301 20:21:02 IDENT=* IP=88.164.x.x REASON=aaa bbb ccc... NOTE=xxx xxx x x x x...";

let regex = /DATEADDED=(.*) IDENT=(.*) IP=(.*) REASON=(.*) NOTE=(.*)/g;

let out = regex.exec(test);

alert(out[1]); //20210301 20:21:02
alert(out[2]); //*
alert(out[3]); //88.164.x.x
alert(out[4]); //aaa bbb ccc...
alert(out[5]); //xxx xxx x x x x...

works well. Question resolved

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement