java - Create array of regex match(multiline) -
i want create array of regex match string text bellow.
.title1 content of title1. content of title1. ..title2 content of title2 content of title2
and desired array below
array[0] = ".title1 content of title1. content of title1." array[1] = "..title2 content of title2 content of title2"
and bellow code.
arraylist<string> array = new arraylist<string>(); pattern p = pattern.compile("^\.[\w|\w]+^\.", pattern.multiline); matcher m = p.matcher(textabove); if(m.matches()){ m.reset(); while(m.find()){ array.add(m.group()); } }
but code, array[0] contains ".title1" "." before ".title2", , couldn't array[1] since m.find() doesn't match, , when use ^\.[\w|\w]+
instead of regex pattern above, array[0] contains everything. how can acheive array? don't stick regex, solution welcome.
you're pretty close - try regex instead:
^\..*?(?=(^\.|\z))
in java, be"
"^\\..*?(?=(^\\.|\\z))" // escaping backslashes java string.
Comments
Post a Comment