Click here to Skip to main content
15,886,052 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public class Math {
	public static void compare(String A, String B) {
		int a;
	    a= S.replaceAll("[^" + J + "]" , "").length();
	String b = S.replaceAll("[^"+ J +"]", "");
	    System.out.println(a is +a);
	    System.out.println(b is +b);
	    
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String A= "AHhB";
		String B="CKDADEGEGAh";
	Math.compare(J, S);
	}<pre lang="java">


}

What I have tried:

Output :a is 3
b is AAh
My Understanding : [^J] matches a characters which is not in String J.
But what is the use of “[^” and “]”
Posted
Updated 13-Apr-18 5:28am
v2
Comments
Patrice T 13-Apr-18 15:40pm    
Are you sure this code is working ?

1 solution

It means all characters that are not in the set in brackets. So [^abc] means any character except a or b or c. See RegExr: Learn, Build, & Test RegEx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900