Java 使用正则表达式从给定字符串中提取子字符串
如何在JDK中使用正则表达式提取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(.+?)\\
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如果有人需要一个想法来做一些努力,该怎么办?就像在这个例子中,如果你不知道如何使用正则表达式,你就不能编写代码来提取子字符串,所以也许我们可以向他们展示如何去做,而不是为他们编写代码