My String to parse is an http response with the separation of vertical bars '|' colons ':' and commas ','
"1701|919422522891:224c1214-bb95-414d-ba76-77db95370545,1701|918275004333:5e93a439-2644-4455-9f01-f27e6cf0cde6"
I have made an attempt to parse with the following code
public void split2(){
String input = "1701|919422522891:224c1214-bb95-414d-ba76-77db95370545," +
"1701|918275004333:5e93a439-2644-4455-9f01-f27e6cf0cde6";
Matcher matcher = Pattern.compile("\\|.*?\\:\\,").matcher(input);
int nr = 0;
while (matcher.find()) {
System.out.println(matcher.group());
}
}
UPDATE - WORKING CODE
The split method works well
public String[] split(String regex,String input)
{
input = "1701|919422522891:224c1214-bb95-414d-ba76-77db95370545," +
"1701|918275004333:5e93a439-2644-4455-9f01-f27e6cf0cde6";
regex = "\\||:|," ;
String[] soso = Pattern.compile(regex).split(input, input.length());
for(String s :soso){
Log.e("",s.toString());
}
return null;
}
You can use:
Matcher matcher = Pattern.compile("[^|]*\\|[^:]*:[^,]*,").matcher(input);
Explanation: This regex "[^|]*\\\\|[^:]*:[^,]*,"
means:
[^|]*
- Match 0 or more characters before a pipe \\\\|
- Match a pipe [^:]*
- Match 0 or more characters before a colon :
- Match a colon [^,]*
- Match 0 or more characters before a comma ,
- Match a coma
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.