import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyRegular {
public static void main(String[] args) {
String regex = "★";
Pattern pattern = Pattern.compile(regex);
String[] strings = { "abc", "abbc", "bc" };
strings = new String[] { "a", "e", "i", "o", "u" };
strings = new String[] { "a48", "b49" };
strings = new String[] { "abc", "abbc", "abbbc" };
Matcher matcher;
regex = "a*(b+)c?";
regex = "[a|e|i|o|u]";
regex = "\\w+\\d+";
regex = "[年月日]";
regex = "元|人民币|RMB";
regex = "a*b+c?";
regex = "([a-zA-Z]{1,6}[0-9]{3})";
regex = "a(b{1,3})c";
regex = "\\s+";
regex = "<(\\w+)>(\\w+)</(\\w+)>";
regex = "[\\w[.-]]+@[\\w[.-]]+\\.[\\w]+";
pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
pattern = Pattern.compile(regex);
String newChar = "¥";
String string = "2011年10月13日";
strings = pattern.split(string);
string = "10元10人民币10RMB".replaceAll(regex, newChar);
string = "abbbc abbc abc";
string = "tomcat127";
string = "name=scott pass=tiger";
string = "<name>scott</name><pass>tiger</pass>";
string = "scott@sina.com";
StringBuffer buffer = new StringBuffer();
for (String input : strings) {
matcher = pattern.matcher(input);
System.out.println(matcher.matches());
if (Pattern.matches(regex, input)) {
System.out.println(input);
}
}
for (matcher = pattern.matcher(string); matcher.find(); matcher
.appendReplacement(buffer, string)) {
string = matcher.group().toUpperCase();
System.out.println(matcher.group());
}
System.out.println(matcher.appendTail(buffer));
}
}