首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OCP 7Ⅱ正则表达式

OCP 7Ⅱ正则表达式
EN

Stack Overflow用户
提问于 2015-01-03 14:40:31
回答 2查看 111关注 0票数 1
代码语言:javascript
复制
import java.util.regex.*;

public class Regex2 {

    public static void main(String[] args) {
        Pattern p = Pattern.compile("\\d*");
        Matcher m = p.matcher("ab34ef");
        boolean b = false;
        while ( m.find()) {
            System.out.print(m.start() + m.group());
        }
    }
}

此代码产生输出的原因: 01234456

EN

回答 2

Stack Overflow用户

发布于 2015-01-03 14:43:37

代码语言:javascript
复制
\d* means integer 0 or more times.So an empty string between a and b ,before a ...those are also

matched.Use `\d+` to get correct result.

见演示。

https://www.regex101.com/r/fG5pZ8/25

票数 1
EN

Stack Overflow用户

发布于 2015-01-03 15:20:17

因为\\d*表示零或更多位数。

作为,

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27755980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档