java - Parse string using pattern and Matcher -


i have string

 str = "-------------date 26032016 hi team, alone. -------------time 206066"; 

i need

hi team, alone.

i using following code

pattern p = pattern.compile("(-*?) h");         matcher m = p.matcher(str);         while (m.find()) {             part = m.group(1);         } pattern p1 = pattern.compile("(.*?) -");         matcher m1 = p1.matcher(part);         while (m1.find()) {             part1 = m1.group(1);         } 

but not working.

i trying find string between date ( eg. -------------date 26032016) , time (for eg. -------------time 206066).

why using several matchers? use:

-*date \\d{8}\n(.*)\n-*time \\d{6} 

this assumes lines whown string value different lines , not accidential line wrap.

otherwise need replace (or delete) \n characters pattern


Comments