我是Regex表达式的新手,所以无法验证字符串,该字符串可以有0-9个FGHC和fghc *#。
我正在尝试使用[0-9FGHCFGHC*#],它使用regex工具,但在java中它不起作用,我正在使用java1.7
E.g.for这个模式,我需要它,像2314F*Ghc 12fgH#等。
public static void main(String[] args){
String money = "23FGhc*#";
Pattern p = Pattern.compile("[0-9FGHCfghc*#]",Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(money);
if (m.matches())
System.out.println("valid:-"+ m);
else
System.out.println("unvalid:- "+m);
}提前感谢你的帮助,这样我才能在RegEx中有更多的知识。
发布于 2016-05-09 09:43:22
(?i)[0-9fghc*#]+您还需要在末尾添加一个量词。在这种情况下,+可以匹配这些字符一次或多次。
也可以添加(?i)使其不区分大小写。
https://stackoverflow.com/questions/37112373
复制相似问题