I am new to Regex expression so not able to validate the String which can have number 0-9 FGHC,and fghc *#.
I am trying with [0-9FGHCFGHC*#]
its working with regex tool but in java its not working.I am using java 1.7
Egfor this pattern I required it like 2314F*Ghc 12fgH#
etc.
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);
}
Thank in Advance for your help and it will be more help that you explain the soultion so I can have more knowledge in RegEx
(?i)[0-9fghc*#]+
You need to add a quantifier at the end as well. In this case +
to match these characters one or more times.
Use can also add (?i)
to make it case insensitive.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.