0

everybody,

I'm having performance problems with my code. An input string looks like this:

'intput = valueA valueB valueC "valueD 13" valueF... valueZ'

The goal is to assign dedicated variables to each value. Currently my code looks like this:

var myArray = intput.split(/ +(?=(?:(?:[^"]*"){2})*[^"]*$)/);
outputOne = myArray[1];
outputTwo = myArray[2];
outputThree = myArray[3];
outputFour = myArray[4];
...
outputX = myArray[30];

It seems, however, that my code is not performant enough. I'd like to process about 500 input strings per second, but I'm currently only able to process about 120.

Even a .exec doesn't change that much. I have tried the following regex:

var myArraytwo =/(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\".*?\")\s(\S+)\s(\S+)\s(\S+)\s/.exec(bufferString)

Is there a faster way to assign the above string to dedicated variables?

qwertzy
  • 29
  • 3
  • Have you tried https://stackoverflow.com/questions/16261635/javascript-split-string-by-space-but-ignore-space-in-quotes-notice-not-to-spli? `/ +(?=(?:(?:[^"]*"){2})*[^"]*$)/` is a very slow pattern. `/[^\s"]+|"[^"]*"/g` should be faster – Wiktor Stribiżew Jun 02 '20 at 10:46
  • Also, see https://stackoverflow.com/a/18703767/3832970. – Wiktor Stribiżew Jun 02 '20 at 10:49

0 Answers0