正则表达式
来源:互联网 发布:lol淘宝权女友辣椒 编辑:程序博客网 时间:2024/04/27 17:49
public class StringUtil {/** * 去除字符串中的特殊字符 * * @param string * @return */public static String clean(String string) {String regEx = "[^A-Za-z\\d\\u4E00-\\u9FA5]+";return clean(string, regEx);}public static String clean(String string, String regEx) {Pattern pattern = Pattern.compile(regEx);Matcher matcher = pattern.matcher(string);return matcher.replaceAll("").trim();}/** * 返回所有匹配的字符串 * * @param regEx * 正则表达式 * @param string */public static List<String> getMatchedStrings(String regEx, String string) {List<String> result = new ArrayList<String>();Pattern pattern = Pattern.compile(regEx);Matcher matcher = pattern.matcher(string);while (matcher.find()) {result.add(matcher.group());}return result;}/** * 检查是否为所需格式 * * @param string * @return */public static boolean isValid(String string) {String regEx = "[A-Za-z\\d\\u4E00-\\u9FA5]+";return isValid(string, regEx);}public static boolean isValid(String string, String regEx) {Pattern pattern = Pattern.compile(regEx);Matcher matcher = pattern.matcher(string);if (matcher.matches()) {return true;}return false;}}
常用JavaScript正则表达式
/*邮箱*//^[a-zA-Z]+[a-zA-Z0-9\._]+@\w+\.[a-z]+$//*数字(正负数、小数)*//^[\+-]?\d|[\+-]?\d+\.\d+$//*数字、字母和汉字*//^[A-Za-z\d\u4E00-\u9FA5]*$//*IPV4*//^(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.)(([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))\.){2}([1-9]|([1-9]\d)|(1\d\d)|(2([0-4]\d|5[0-5])))$/
- 【正则表达式】正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 正则表达式
- 为DataGride单元格添加背景色 .
- 在android应用市场中直接定位到自己的应用
- const成员函数返回数组名
- Android系统的开机画面显示过程分析
- 关于闭包中的this
- 正则表达式
- 数据结构之二叉树(3)
- POJ 1986 Distance Queries(LCA)
- ssh整合中出现的问题的总结
- 程序员就业文章推荐
- Linux (RHEL 5.4)下安装 Oracle 10g R2
- Log4Delphi
- iptables rules to allowL2TP/IPSEC VPN behind firewall
- VMWare虚拟机下为Ubuntu 12.04.1配置静态IP(NAT方式)