集册 Java实例教程 在正则表达式中按数字拆分字符串

在正则表达式中按数字拆分字符串

欢马劈雪     最近更新时间:2020-01-02 10:19:05

402
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
在正则表达式中按数字拆分字符串

import java.util.regex.Pattern;

import java.util.regex.Matcher;


public class SplitDemo2 {
/* 
 来自 
*时 代 J a v a 公 众 号*/


    private static final String REGEX = "\\d";

    private static final String INPUT = "one9two4three7four1five";


    public static void main(String[] args) {

        Pattern p = Pattern.compile(REGEX);

        String[] items = p.split(INPUT);

        for (String s : items) {

            System.out.println(s);

        }

    }

}


展开阅读全文