我刚开始java.util.regex主题。我可以执行以下代码并获得满意的结果。我在代码中使用了无限循环,试图通过给出条件来打破。然而它并没有以某种方式打破。有什么想法吗?
import java.util.Scanner;
import java.util.regex.*;
import javax.swing.JOptionPane;
public class RegEx {
public static void main(String[] args){
//using system input for Pattern and Matcher classes
Scanner regex = new Scanner(System.in);
while(true){
System.out.println("regex please: ");
Pattern p1 = Pattern.compile(regex.nextLine());
System.out.println("input please: ");
Matcher m1 = p1.matcher(regex.nextLine());
boolean b2 = m1.matches();
System.out.println("your input \""+m1.group()+"\" is matching and "+b2);
if(JOptionPane.showInputDialog("does it match: ").equals("Yes")){
System.out.println("take rest now");
break;
}//note sure why this condition is not working
}
}
}
尝试使用
if(JOptionPane.showInputDialog("does it match: ").trim().equalsIgnoreCase("yes"))
{
//your code
}