`
- 浏览:
741005 次
- 性别:
- 来自:
深圳
-
- package com.ygj.util;
-
-
import java.util.*;
-
-
import org.apache.oro.text.regex.*;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public final class Regexp
- {
-
-
-
static final Set SEPARATOR_SET=new TreeSet();
- {
-
SEPARATOR_SET.add("(");
-
SEPARATOR_SET.add(")");
-
SEPARATOR_SET.add("[");
-
SEPARATOR_SET.add("]");
-
SEPARATOR_SET.add("{");
-
SEPARATOR_SET.add("}");
-
SEPARATOR_SET.add("<");
-
SEPARATOR_SET.add(">");
- }
-
-
-
-
public static HashMap regexpHash = new HashMap();
-
-
-
public static List matchingResultList = new ArrayList();
-
-
private Regexp()
- {
-
- }
-
-
-
-
-
public static Regexp getInstance()
- {
-
return new Regexp();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String icon_regexp = "^(/{0,1}\\w){1,}\\.(gif|dmp|png|jpg)$|^\\w{1,}\\.(gif|dmp|png|jpg)$";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String email_regexp = "(?:\\w[-._\\w]*\\w@\\w[-._\\w]*\\w\\.\\w{2,3}$)";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String url_regexp = "(\\w+)://([^/:]+)(:\\d*)?([^#\\s]*)";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String http_regexp = "(http|https|ftp)://([^/:]+)(:\\d*)?([^#\\s]*)";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String date_regexp = "^((((19){1}|(20){1})d{2})|d{2})[-\\s]{1}[01]{1}d{1}[-\\s]{1}[0-3]{1}d{1}$";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String phone_regexp = "^(?:0[0-9]{2,3}[-\\s]{1}|\\(0[0-9]{2,4}\\))[0-9]{6,8}$
|^[1-9]{1}[0-9]{5,7}$|^[1-9]{1}[0-9]{10}$";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String ID_card_regexp = "^\\d{10}|\\d{13}|\\d{15}|\\d{18}$";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String ZIP_regexp = "^[0-9]{6}$";
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
public static final String non_special_char_regexp = "^[^'\"\\;,:-<>\\s].+$";
-
-
-
-
-
-
public static final String non_negative_integers_regexp = "^\\d+$";
-
-
-
-
-
public static final String non_zero_negative_integers_regexp = "^[1-9]+\\d*$";
-
-
-
-
-
-
-
public static final String positive_integer_regexp = "^[0-9]*[1-9][0-9]*$";
-
-
-
-
-
-
-
public static final String non_positive_integers_regexp = "^((-\\d+)|(0+))$";
-
-
-
-
-
-
-
public static final String negative_integers_regexp = "^-[0-9]*[1-9][0-9]*$";
-
-
-
-
-
-
-
public static final String integer_regexp = "^-?\\d+$";
-
-
-
-
-
-
-
public static final String non_negative_rational_numbers_regexp = "^\\d+(\\.\\d+)?$";
-
-
-
-
-
-
-
public static final String positive_rational_numbers_regexp = "^(([0-9]+\\.[0-9]*[1-9][0-9]*)
|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$";
-
-
-
-
-
-
-
public static final String non_positive_rational_numbers_regexp = "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$";
-
-
-
-
-
-
-
public static final String negative_rational_numbers_regexp = "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)
|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$";
-
-
-
-
-
-
-
public static final String rational_numbers_regexp = "^(-?\\d+)(\\.\\d+)?$";
-
-
-
-
-
-
-
public static final String letter_regexp = "^[A-Za-z]+$";
-
-
-
-
-
-
-
public static final String upward_letter_regexp = "^[A-Z]+$";
-
-
-
-
-
-
-
public static final String lower_letter_regexp = "^[a-z]+$";
-
-
-
-
-
-
-
public static final String letter_number_regexp = "^[A-Za-z0-9]+$";
-
-
-
-
-
-
-
public static final String letter_number_underline_regexp = "^\\w+$";
-
-
-
-
-
-
-
-
-
-
public void putRegexpHash(String regexpName, String regexp)
- {
- regexpHash.put(regexpName, regexp);
- }
-
-
-
-
-
-
-
-
-
-
public String getRegexpHash(String regexpName)
- {
-
if (regexpHash.get(regexpName) != null)
- {
-
return ((String) regexpHash.get(regexpName));
- }
-
else
- {
-
System.out.println("在regexpHash中没有此正规表达式");
-
return "";
- }
- }
-
-
-
-
-
public void clearRegexpHash()
- {
- regexpHash.clear();
-
return;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
public static boolean isHardRegexpValidate(String source, String regexp)
- {
-
-
try
- {
-
-
PatternCompiler compiler = new Perl5Compiler();
-
-
-
PatternMatcher matcher = new Perl5Matcher();
-
-
- Pattern hardPattern = compiler.compile(regexp);
-
-
-
return matcher.contains(source, hardPattern);
-
- }
-
catch (MalformedPatternException e)
- {
- e.printStackTrace();
-
- }
-
return false;
- }
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
如果你不熟悉这个术语,那么“正则表达式”(Regular Expression)就是一个字符构成的串,它定义了一个用来搜索匹配字符串的模式。 许多语言,包括Perl、PHP、Python、JavaScript和JScript,都支持用正则表达式处理...
java 利用正则表达式从字符串中提取省、市、区、镇、乡等区域名称(包含少数民族地区),支持地址中无省,无市,无县情况。
主要介绍了Java使用正则表达式提取XML节点内容的方法,结合具体实例形式分析了java针对xml格式字符串的正则匹配相关操作技巧,需要的朋友可以参考下
最新手机号码、电话号码正则表达式
其中包括5个类,这5个类的代码基本概括了java正则表达式替换String的多种情况,比如获取某个文件路径中盘符/后边的部分内容,提取"<title>XXXX</title>"中的文字XXXX,用正则表达式获取指定字符串内容中的指定内容,...
JAVA正则表达式应用:任意输入一串字符串 如何输入exit退出程序;从输入的字符串中判断是否包含手机号码 正则表达式可以使用" +86| 86 1 d{10}" 如果包含请将其在控制台打印出来 否则输出不包含字符串 ...
写个可以匹配一下各种特殊字符的正则表达式 ((?=[\x21-\x7e]+)[^A-Za-z0-9]) x21-\x7e]+)[^A-Za-z0-9]) 这个匹配所有键盘上可见的非字母和数字的符号 var patrn = /[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~...
说某个字符串匹配某个正则表达式,通常是指这个字符串里有一部分(或几部分分别)能满足表达式给出的条件。 在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要。正则表达式就是用于描述...
大家都知道,正则表达式是一种可以用于模式匹配和替换的规范,一个正则表达式就是由普通的字符(例如字符a到z)以及特殊字符(元字符)组成的文字模式,它用以描述在查找文字主体时待匹配的一个或多个字符串。正则...
正则表达式来匹配字符串是比较合适的 选择
LeetCode问题10要求解决的是"正则表达式匹配"问题,具体来说是实现一个函数来判断一个字符串是否与一个给定的模式匹配,这里的模式可以包含.和*字符,其中.匹配任意单个字符,*表示它前面的字符可以出现任意次(包括...
匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包括汉字在内):[^\x00-\xff] 评注:可以用来计算字符串的长度(一个双字节字符长度计2,...
今天在Java中想使用正则表达式来获取一段文本中的任意字符。于是很随意得就写出如下匹配规则: (.*) 结果运行之后才发现,无法获得换行之后的文本。于是查了一下手册,才发现正则表达式中,“.”(点符号)匹配的是...
Java正则表达式在字符串处理和模式匹配中扮演着重要角色。为了帮助准备面试的你更好地掌握Java正则表达式的应用,本文精选了20道复杂的面试题,并提供了详细的解析。从贪婪匹配和非贪婪匹配的概念到匹配数字、字母、...
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1) 匹配空白行的正则表达式:ns*r 评注:可以用来删除空白行 匹配HTML标记的正则表达式:(S*?)[^>]*>.*?|*? /> 评注:网上流传的版本太...
java代码,从image标签中正则匹配取出src标签的内容,java代码,从image标签中正则匹配取出src标签的内容
函数 clean 的功能是:屏蔽字符串参数 text 中的网页链接信息,并返回屏蔽后的结果; 如果无需屏蔽,则返回原来的字符串. 每个网页链接从左至右依次分成前缀,域名和后缀 三部分,各部分定义如下: 1) 前缀是以下三...
2) String replaceAll(String regex,String replacement):返回该字符串中所有匹配正则表达式的子串,然后替换成replacement指定的字符串。 3) String replaceFirst(String regex,String replacement);返回该字符...
如果你不熟悉这个术语,那么“正则表达式”(Regular Expression)就是一个字符构成的串,它定义了一个用来搜索匹配字符串的模式。 许多语言,包括Perl、PHP、Python、JavaScript和JScript,都支持用正则表达式处理...
如果你曾经用过Perl或任何其他内建正则表达式支持的语言,你一定知道用正则表达式...如果你不熟悉这个术语,那么“正则表达式”(Regular Expression)就是一个字符构成的串,它定义了一个用来搜索匹配字符串的模式。