regex - using regular expression in Java -


I need to check a string in which only ABCDFG characters should be in any order and with only 7 characters . Please tell me the correct way to use regular expressions.

As I am using

  string abs = "ABPID"; If (! Pattern.matches ("[[ABCDEFG]", abs) System.out.println ("Error");  

I am using the following code which works while using string ABCDFG, but in other cases it fails. Please help me

to see if string ABCDEFG , implementing any duplicates It's easy to look negative and with the capturing group:

  ^ (? !!. *.) * \ 1) [AG] {7} $  

You do not need anchor if you use String.matches () in Java here Testing has been used:

  string [] test = {"ABCDEFG", / / ​​"true" GBADFEC ", // true" ABCADFG ", // false}; ( String Test: Test) {System.out.format ("% s% b% n", test, test.matches ("(?!. *.). * \\ 1) [AG] {7}")) ;}  

Actually, [AG] {7} , but (?!. * (.). * 1) That's it, no letters are repeated.

string [] test = {"abcdeb", "//" (b) "ABCDFG", "ABCD FAG" "ABA", "" (A) "" ABCEFGXIJIAI "//" (Y) "} ; (String Test: Test) {System.out.println (test.replaceAll ("(? =. * (.). * \\ 1)." "," ($ 1) ")); }

It works the way . * (.) Trying to match * \ 1 , that is, . * In the middle, a capture character (.) which appears again \ 1 .

Also see


Comments