使用REGEX从给定字符串中提取子字符串

时间:2013-06-11 21:14:58

标签: java regex

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

如何在JDK中使用REGEX提取AWSDataTransfertheproduct之间的单词)?

1 个答案:

答案 0 :(得分:4)

像这样:

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));
}

输出:

AWSDataTransfer