I want a regular expression that matches as following
String myString =
"11 22 01 02 22 11
11 22 31 32 22 11
11 22 51 42 22 11 ......"
i want to match both starting 11 22 and ending string 22 11 sequence and also i want to split the string into array of 01 02,31 32,51 42, ....
String[] resultArray = myString.split("11 22 .* 22 11");
I am getting only empty array with proper size of 11 22 xxx 22 11 sequence.
You can use groups for that purpose.
Pattern p = Pattern.compile("MY TEXT (.*) MY TEXT MY TEXT (.*) My TEXT");
Matcher m = p.matcher("MY TEXT hello you MY TEXT MY TEXT are here My TEXT");
if (m.find()) {
System.out.println(m.group(1)); // prints 'hello you'
System.out.println(m.group(2)); // prints 'are here'
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.