1、获取一个字符串后面的数据:
String photoPath = "/myword-front/resources/photo/admin/bd5f9model_tree1.jpg";
目前想要/myword-front后面的数据:
Pattern pattern = Pattern.compile("/myword-front(.*)");
Matcher m = pattern.matcher(photoPath);
if (m.find()) {
oldPath = m.group(1);
}
2、获取json数据格式的某一个属性数据:
JsonData = {"username":"jasyca","checkCodeLink":"http://www.alibaba.com/....."}
目前想要得到checkCodeLink后面的url:
Pattern pattern = Pattern.compile("\'checkCodeLink\' : '(.*)'");
Matcher m = pattern.matcher(JsonData);
if (m.find()) {
this.checkCodeLink = m.group(1); // 得到图片验证码地址
}
3、
private String parseLogout(String responseBody) {
Pattern p = Pattern.compile("location.href = \\'(.*)\\'");
Matcher m = p.matcher(responseBody);
if (m.find()) {
return m.group(1);
}
return null;
}
4、
Pattern pattern = Pattern.compile("returnMsg.pushMsg.'(.*)',.*,.*;");
5、
Pattern p1 = Pattern.compile("POSTDATAMAP.securityCodeUrl = \\'(.*?)\\'");
6、获得 your 后面的字符串:
Pattern p = Pattern.compile("^(.*)your(.*)$");
Matcher m = p.matcher(e.attr("value"));
String keywordsStr = m.group(2);
7、js 去掉多余的空格(多余两个的情况,换成1个空格) ----replace(/\s+/g, ' ')
8、java去除连续的空格只保留一个
word = Pattern.compile("\\s{2,}").matcher(word.trim()).replaceAll(" ");
9、去掉字符串里面的汉字和多余的空格
var pattern_chin = /[\u4e00-\u9fa5]/g; //汉字的正则表达式
var matchResult = content.match(pattern_chin);
if(matchResult != null){
content = content.replace(pattern_chin,' ').trim().replace(/\s+/g, ' ');
ue.setContent(content);
}
10、输入正数、负数、小数的正则:
var patter_INT = /^[+-]?([1-9][0-9]*|0)(\.[0-9]+)?$/;
var matchInt_1 = patter_INT.test(value_1);
if(value_1 != "" && !matchInt_1){
LIRight.next("div").find(".ui2-feedback-title").text("请输入有效数字");
LIRight.next("div").show();
}
11、/^[+-]?([1-9][0-9]*|0)(\.[0-9]+)?%?$/ 正数,负数,百分数都可以
12、var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;