Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.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,如何在JDK中使用正则表达式提取AWSDataTransfer(在与产品之间的单词) String s="For the AWSDataTransfer product, this is the public pricing plan"; 输出: String s="For the AWSDataTransfer product, this is the public pricing plan"; Pattern pattern = Pattern.compile("the\\s(.+?)\\

如何在JDK中使用正则表达式提取
AWSDataTransfer
(在
产品之间的单词)

String s="For the AWSDataTransfer product, this is the public pricing plan";
输出:

String s="For the AWSDataTransfer product, this is the public pricing plan";
Pattern pattern = Pattern.compile("the\\s(.+?)\\sproduct");
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
    System.out.println(matcher.group(1));
}
像这样:

String s="For the AWSDataTransfer product, this is the public pricing plan";
输出:

String s="For the AWSDataTransfer product, this is the public pricing plan";
Pattern pattern = Pattern.compile("the\\s(.+?)\\sproduct");
Matcher matcher = pattern.matcher(s);
if (matcher.find()) {
    System.out.println(matcher.group(1));
}

Stackoverflow不是一个让人们为你工作和编写代码的网站。如果您有特殊问题,我们很乐意帮助您解决您的难题。因此,展示一些努力,并发布一些您尝试过但不起作用的代码。@m.buettner如果有人需要一个想法来做一些努力,该怎么办?就像在这种情况下,如果你不知道如何使用正则表达式,你就不能编写代码来提取子字符串,所以也许我们可以向他们展示如何做,而不是为他们编写代码。这永远是第三个词吗?Stackoverflow不是一个让人们为你工作并为你编写代码的网站。如果您有特殊问题,我们很乐意帮助您解决您的难题。因此,展示一些努力,并发布一些您尝试过但不起作用的代码。@m.buettner如果有人需要一个想法来做一些努力,该怎么办?就像在这个例子中,如果你不知道如何使用正则表达式,你就不能编写代码来提取子字符串,所以也许我们可以向他们展示如何去做,而不是为他们编写代码