Use a regular expression to match the input content ---- Regular Expression
// Use a regular expression to match the input content
Package regex;
Import java. util. collections;
Import java. util. regex. Matcher;
Import java. util. regex. Pattern;
Public class RegexTest {
Public static void main (String [] args ){
// TODO Auto-generated method stub
Running in = new Processing (System. in );
System. out. println ("Enter pattern :");
String patternString = in. nextLine ();
Pattern pattern = Pattern. compile (patternString );
While (true ){
System. out. println ("Enter String to match :");
String input = in. nextLine ();
If (input = null | input. equals (""))
Return;
Matcher matcher = pattern. matcher (input );
If (matcher. matches ()){
System. out. println ("Match ");
Int g = matcher. groupCount ();
If (g> 0 ){
For (int I = 0; I <input. length (); I ++ ){
For (int j = 1; j <= g; j ++ ){
If (I = matcher. start (j) & I = matcher. end (j )){
System. out. println ("()");
}
}
For (int j = 1; j <= g; j ++ ){
If (I = matcher. start (j) & I! = Matcher. end (j )){
System. out. println ('(');
}
}
System. out. println (input. charAt (I ));
For (int j = 1; j <= g; j ++ ){
If (I + 1! = Matcher. start (j) & I + 1 = matcher. end (j )){
System. out. println (')');
}
}
}
System. out. println ();
}
}
Else
System. out. println ("No match ");
}
}
}