I want to create array of javascript’s regexp match string from the text below.
.root
this is root
..child 1
this is child 1
this is also child 1's content.
...child 1-1
this is child 1-1
..child 2
this is child 2
...child 2-1
this is child 2-1
.root 2
this is root 2
and desired array is below
array[0] = ".root
this is root"
array[1] = "..child 1
this is child 1
this is also child 1's content"
array[2] = "...child 1-1
this is child 1-1
"
array[3] = "..child 2
this is child 2"
array[4] = "...child 2-1
this is child 2-1"
array[5] = ".root 2
this is root 2"
In Java, I can do like ^\..*?(?=(^\.|\Z)), but in Javascript there is no \Z, . doesn’t match newline character, and $ matches newline character (not just the end of string).
How can I achieve this array?
I use this site ( http://www.gethifi.com/tools/regex ) to test regexp.
text.split(/\r?\n^(?=\.)/gm)produces the same array.text.match(/^\..*(\r?\n[^.].*)*/gm)ugly, but still.