我是java和正則表達式的新手,我想知道匹配的正則表達式是「A」還是「OO」或「NC」。我將它與文本文件進行比較。我讀了其他線程並嘗試了它們,但我無法做到這一點。我的主要方法也有問題,說未報告的異常請幫助。獲取匹配的java正則表達式
UserLogin.java
public static String userLoginVerify(String actNum,String pass) throws FileNotFoundException
{
Scanner scan = null;
AtmMenu atm = new AtmMenu();
try {
scan = new Scanner(new BufferedReader(new FileReader("atm\\atmstatus.flat")));
while(scan.hasNext())
{
String lines;
lines = scan.nextLine();
Pattern pattern = Pattern.compile("[A]||[OO]||[NC]");
Matcher matcher = pattern.matcher(lines);
if(matcher.find()) {
System.out.println(matcher.group(1));
}
}
}catch(FileNotFoundException filenotfound)
{
System.out.println("File \"atmstatus.flat\" can't be found!");
}
finally
{
if(scan != null)
scan.close();
return "me";
}
}
mainmethod這裏
public static void main(String[] login)
{
passLoginInfo(login[0],login[1]);
}
public static void passLoginInfo(String accountNumber, String password)
{
UserLogin userLogin = new UserLogin();
userLogin.userLoginVerify(accountNumber, password);
}
Here'd我檢查
currentamount | stat
P500,000,000,000,000,000.00 | A
我檢查的統計信文件
這是非常不清楚,你想用正則表達式做什麼 - 但就異常問題而言 - 你有多少理解檢查異常?你應該閱讀http://docs.oracle.com/javase/tutorial/essential/exceptions/ –
你只是想檢查一個字符串是「A」,「OO」還是「NC」? – Michael
是的,我想檢查它是否與任一字符串匹配。我會發布我正在檢查的文件 – Ley47