-1

I am looking for a regex expression to split the following type of data:

<exp>(;<exp>)*

and receive a list of every exp but not the delimiter ';'.

So far I have ([^;])(?:;([^;])) but this regex stops at the first exp after ';'. Is there any way to make the lookahead infinite?

Here is a concrete example:

23;hello;2452;ad34aa;bye

I want to get:

[0] = 23
[1] = hello
[2] = 2452
[3] = ad34aa
[4] = bye

I apologize if this question has been answered but I have been unable to find a working expression. If it has please tell me the link.

Thanks for taking the time to read this :)

rock321987
  • 10,942
  • 1
  • 30
  • 43
user3438286
  • 93
  • 1
  • 6

1 Answers1

4

Use String#split

var array = '23;hello;2452;ad34aa;bye'.split(';');
document.write('<pre>' + JSON.stringify(array, 0, 4) + '</pre>');

// as mentioned from Avinash Raj
var array2 = '23;hello;2452;ad34aa;bye'.match(/[^;]+/g);
document.write('<pre>' + JSON.stringify(array2, 0, 4) + '</pre>');
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392