问题描述
如何用最短的脚本获取“=”后的每个值?
DATEADDED=20210301 20:21:02 IDENT=* IP=88.164.x.x REASON=aaa bbb ccc... NOTE=xxx xxx x x x x...
把所有东西放在一个数组中
示例:
数组的结果响应:public static class RectangleDriver {}
解决方法
最后,我的灵感来自我在源代码中拥有很长时间的另一个代码:
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...
效果很好。 问题已解决