import java.util.Scanner;
public class UseRegularExpression {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
String str = "abcdefgabcabc";
System.out.println(str.replaceAll(".bc", "###"));
System.out.print("手机: ");
str = scanner.next();
if(str.matches("[0-9]{4}-[0-9]{6}"))
System.out.println("Yes");
else
System.out.println("No");
System.out.print("href标签: ");
str = scanner.next() + " " + scanner.next();
if(str.matches("<a.+href*=*['\"]?.*?['\"]?.*?>"))
System.out.println("Yes");
else
System.out.println("No");
System.out.print("邮箱: ");
str = scanner.next();
if(str.matches("^[_a-z0-9-]+([.][_a-z0-9-]+)*@[a-z0-9-]+([.][a-z0-
9-]+)*$"))
System.out.println("Yes");
else
System.out.println("No");
}
}
C:\Documents and Settings\Administrator\java>java UseRegularExpression
###defg######
手机: 0988-100432
Yes
href标签: ^P^PDBUFSQJMMBS^OPOMZGVO^OOFU^C^_
asd
No
邮箱: justin@cat.onlyfun.net
Yes
文章评论(0条评论)
登录后参与讨论