vicky9988 vicky9988 - 1 year ago 64
Java Question

Regex Expression for Specific string in Java

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

its working with regex tool but in java its not working.I am using java 1.7

E.g.for this pattern I required it like

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);
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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download