-1

我对 RegEx 还很陌生,想参与这个问题。

这是一个例子:

String string = "John gets a Star Wars ticket" + \n
                "Keith gets a soccer ticket" + \n
                "Mary gets a Star Wars ticket"

什么是正则表达式,因此对于其中包含的行,输出将如下所示 Star Wars

John gets a Star Wars ticket
Mary gets a Star Wars ticket

谢谢。

4

1 回答 1

0
    String string = "John gets a Star Wars ticket\n" +
            "Keith gets a soccer ticket\n" +
            "Mary gets a Star Wars ticket";
    for (String line : string.split("\n")) {
        if (line.matches(".*Star Wars.*")) {
            System.out.println(line);
        }
    }
于 2013-03-24T02:03:57.613 回答