Java (Regex?) split string between number/letter combination

前端 未结 5 1947
甜味超标
甜味超标 2021-01-05 08:44

I\'ve been looking through pages and pages of Google results but haven\'t come across anything that could help me.

What I\'m trying to do is split a string like

5条回答
  •  隐瞒了意图╮
    2021-01-05 09:20

    This should do what you want:

    import java.util.regex.*;
    
    String d = "Bananas22Apples496Pears3"
    
    Pattern p = Pattern.compile("[A-Za-z]+|[0-9]+");
    
    Matcher m = p.matcher(d);
    
    while (m.find()) {
          System.out.println(m.group());
    }
    
    // Bananas
    // 22
    // Apples
    // 496
    // Pears
    // 3
    

提交回复
热议问题