您的位置:首页 > 其它

正则表达式的简单应用实例

2008-05-25 04:17 746 查看
google_ad_client = "pub-8800625213955058";

/* 336x280, 创建于 07-11-21 */

google_ad_slot = "0989131976";

google_ad_width = 336;

google_ad_height = 280;

//

import java.io.*;

import java.util.regex.*;

public class Printer {

public static void main(String[] args) {

System.out.println("
Please enter the input string:
");

BufferedReader reader =

new BufferedReader(new InputStreamReader(System.in));

String inputString;

boolean isOK = false;

try {

while(!isOK) {

if((inputString = reader.readLine()) != null) {

if(inputString.length() > 200) {

System.out.println("The string

exceeds 200 characters.
Please enter again!
");

}

else {

Pattern regex = Pattern.compile("[^@#$%&*/^] ");

Matcher matcher = regex.matcher(inputString);

boolean isMatched = matcher.matches();

if(!isMatched) {

System.out.println("The String cant

contain @,#,$,%,*,& and ^.
Please enter again!
");

}

else {

isOK = true;

System.out.println("
Your input

string is:
" inputString);

}

}

}

}

}

catch(IOException e) {

e.printStackTrace();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: