[英]What is the regex for the finding the string with the pattern ALXXXXX in another string?
我想在另一个字符串中找到模式ALXXXXX的字符串。
例如,我要查找字符串数据阶段AL00123的字符串AL00123
我在Java中尝试了以下内容。
Pattern pattern = Pattern.compile("AL\\d\\d\\d\\d\\d");
Matcher matcher = pattern.matcher(searchString);
boolean matches = matcher.matches();
这总是返回false。 我的代码出了什么问题?
我想实现以下目标
以下是ALXXXXX可能以下列任何一种方式发生的各种方式
最后
使用Matcher#matches
将正则表达式模式与整个输入字符串进行匹配。 您想要使用find
。
您还可以将正则表达式降低到AL\\\\d{5}
。
您正在使用Matcher.matches()
,如果字符串完全符合模式,则只返回true
。 为了您的目的,您将要使用Matcher.find()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.