Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 拆分字符串的数字列表_Java_Regex - Fatal编程技术网

Java 拆分字符串的数字列表

Java 拆分字符串的数字列表,java,regex,Java,Regex,我有一个String列表,但没有正则表达式方面的技能。所以我需要你的帮助 第一个字符串: [begin] 65. This tutorial walks you through a series of exercises to get familiar with Kotlin. 66. Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax. 67. Each exercise is c

我有一个
String
列表,但没有正则表达式方面的技能。所以我需要你的帮助

第一个字符串:

[begin]
65. This tutorial walks you through a series of exercises to get familiar with Kotlin. 
66. Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax.
67. Each exercise is created as a failing unit test and your job is to make it pass. You can play with Koans online or offline by cloning the project on GitHub:
...
[end]
二线

[begin]
63. Download the Koans by cloning the project from GitHub
64. Open up the project in IntelliJ IDEA or your favorite editor. Note: If IntelliJ IDEA prompts you to update the Kotlin library, just click yes.
[end]
和其他字符串

目标: 我需要将每个数字行提取为
字符串

String#1 : 63. Download the Koans by cloning the project from GitHub
String#2 : 64. Open up the project in IntelliJ IDEA or your favorite editor. Note: If IntelliJ IDEA prompts you to update the Kotlin library, just click yes.
String#3 : 65. This tutorial walks you through a series of exercises to get familiar with Kotlin. 
String#4 : 66. Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax.
String#5 : 67. Each exercise is created as a failing unit test and your job is to make it pass. You can play with Koans online or offline by cloning the project on GitHub:

各位将非常感谢任何有关skill up regex的在线培训工具。

此工具适用于javascript
/^(\d+)/gm


我希望您的regexp应该如下所示
^(\d+.*)
在哪里

你可以在:rubular.com上玩它

我走这条路:

  • 定义一个类来分析行和文本。。(您需要它来排序最终的
    列表



    .

    直接用谷歌搜索“regex”,你就能找到你需要的所有工具。“英雄看起来不容易:D”是什么意思?英雄们可能会使用必要的资源来完成你拒绝做的事情。像这样的事情?嘘,我糊涂了。你想按行号重新排序吗?真正的英雄要求其他人做他们的工作,为他们解决他们的问题,不费吹灰之力。愿上帝保佑这些勇敢的灵魂。
    ^ - start of line
    \d+ - any non zero amount of numbers
    .*  - any symbols
    ( ) - grouping
    
    class TextLine implements Comparable<TextLine> {
    
        private int line;
        private String lineText;
    
        public TextLine(int line, String lineText) {
            this.line = line;
            this.lineText = lineText;
        }
    
        @Override
        public String toString() {
            return "String:" + line + lineText;
        }
    
        @Override
        public int compareTo(TextLine o) {
            return Integer.compare(this.line, o.line);
        }
    }
    
    public class TestApp {
    
        private List<TextLine> output = new ArrayList<TextLine>();
    
        public static void main(String[] args) {
            TestApp tt = new TestApp();
            String str = "65. This tutorial walks you through a series of exercises to get familiar with Kotlin. ";
            tt.populateLsit(str);
            str = "67. Each exercise is created as a failing unit test and your job is to make it pass. You can play with Koans online or offline by cloning the project on GitHub:";
            tt.populateLsit(str);
            str = "66. Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax. ";
            tt.populateLsit(str);
            str = "63. Download the Koans by cloning the project from GitHub";
            tt.populateLsit(str);
            str = "64. Open up the project in IntelliJ IDEA or your favorite editor. Note: If IntelliJ IDEA prompts you to update the Kotlin library, just click yes.";
            tt.populateLsit(str);
            tt.sortPrint();
        }
    
        private void sortPrint() {
            Collections.sort(output);
            System.out.println(output);
    
        }
    
        private void populateLsit(String str) {
            Matcher match = Pattern.compile("^(\\d+)|(.*)").matcher(str);
            // String r = match.group();
            match.find();
            int i = Integer.parseInt(match.group());
            match.find();
            String s = match.group();
            output.add(new TextLine(i, s));
        }
    }