gpt4 book ai didi

java - 需要一种方法来打印 java 中正则表达式模式的先行部分吗?

转载 作者:行者123 更新时间:2023-12-02 06:47:06 24 4
gpt4 key购买 nike

    String test = page;    Pattern p = Pattern.compile("^\\W+\\s(?=\\w+)");    Matcher m = p.matcher(test);    while(m.find())         System.out.println(m.group());

页面字符串如下所示:

InterestUnknown Unknown’s I do not own or know of any assets that should be listed in this category.$125Net value of all Home property (Schedules A through H)$128Net value of all Bank property (Schedule I)$253Net value of all property (Schedules A through I)

我需要存储最后一个值,比如 253 如何使用正则表达式找到它,然后将其保存在字符串中。

最佳答案

    String s = "Interest\n"
+ "Unknown Unknown’s \n"
+ "I do not own or know of any assets that should be listed in this category.\n"
+ "$125\n"
+ "Net value of all Home property (Schedules A through H)\n"
+ "$128\n"
+ "Net value of all Bank property (Schedule I)\n"
+ "$253\n"
+ "Net value of all property (Schedules A through I)";
Pattern p = Pattern.compile("(?<=\\$)\\d+");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group());
}

输出:

125128253

关于java - 需要一种方法来打印 java 中正则表达式模式的先行部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18529296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com