javascript - Split string data into array based on new line and then double digit number -


What do I have to do, the data is split from an array into an array.

Here's the general idea of ​​the text format ...

xxxxx alpha-numeric is Whatspes refers to any combination of data.

  xxxxx 1 xxxxxxxxxx 2 xxxxxxxxxx xxxxxxxxx Xxxxxxxxx xxxxxxxx 3 xxxxxxxxxx 4 xxxxxxxxxx xxxxxxxxxx 5 xxxxxxxxxx  

(pick one when the number comes in double digits, empty location is in front of the number)

now I have to do that, he has an array of 5 elements (in this case), which numbers and track all data (including new lines). It was not a great deal in the past and I could use the string.split ("\ n") , but now I have some types of reggues like / \ n [0-9] ] {1,2} / So I'm looking for a quick and easy way to do this (as the partition does not support regex).

I want to array [3] = "3 xxxxxxxxxx" ... etc.

  array [1] = "1 xxxxxxxxxx" array [2] = " 2 xxxxxxxxxxx \ nxxxxxxxxxx \ nxxxxxxxxxx "array [/ code>   

You can use lookahead and < code> split (? = [1-9] | [1- 9] [0- 9]) , perhaps anchored at the beginning of a line, but xxxx ambiguity in part There may be problems with this, it also does not ensure that the number is gradual.

Example

  var text = "preface \ n" + "1 Introduction \ n" + "2 body \ N" + "more body \ n" + "3 Goods \ n "+" More Things \ n "+" Even 4 Things \ n "+" 10 Conclusions \ n "+" 13 Appendix \ n "; Print (text split (/ ^ (? = [1-9] | [1- 9] [0- 9]) / M));  

Output is ():

  Introduction, 1 Introduction, 2 body and body, 3 belongings and accessories also 4 items, 10 findings, 13 addendum < / Code> 

Comments