java正则表达式,将字符串中\后的第一个字母变成大写 例子是比较简单,注意的是java中的“\\”意义是:我要插入一个正则表达式的反斜线,所以其后面的字符有特殊有意义.所以普通反斜线应该是"\\\\" String in = "\\a\\bnf\\fv"; System.out.println("in is= " + in); StringBuffer sb = new StringBuffer(); Pattern p = Pattern.c…
首先说一下java正则表达式的重点概念: 第一.相关类:Pattern.Matcher 第二.典型的调用顺序是 Pattern p = Pattern.compile("a*b"); Matcher m = p.matcher("aaaaab"); boolean b = m.matches(); 在仅使用一次正则表达式时,可以方便地通过此类定义 matches 方法.此方法编译表达式并在单个调用中将输入序列与其匹配. 语句 boolean b = Pattern.…
用正则表达式执行查找命令,则需要用正则对象,其规则和执行顺序如下: 指定为字符串的正则表达式必须首先被便以为此类的实例.然后,可将得到的正则对象匹配任意的字符串用于创建Mather对象,执行匹配所涉及的所有状态都驻留在匹配其中,所以多个匹配器可以共享同一个模式. 查找需要使用的对象:Pattern 正则对象Matcher 匹配器对象 因此,典型的调用顺序为: Pattern p = Pattern.compile("正则"); Matcher m = p.matcher("a…
今天在项目里看到用 Python 正则表达式的时候,用到 group,没有仔细看.正好学习 Java 正则表达式,对 group 多留意了一下. 上代码: import java.util.regex.*; class RegexExample2{ public static void main(String[] args) { String content = " /udisk/123 /udisk/1 /udisk/2"; String pattern = "\\s(/u…
import java.util.regex.Matcher;import java.util.regex.Pattern; public class Main { public static void main(String[] args) throws Exception { String str = "10.2368686986859686"; Pattern p = Pattern.compile("[\\d]*[\\.][\\d]{2}"); // 小数保…
import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegexMatches { public static void main( String args[] ){ // 按指定模式在字符串查找 String line = "This order was placed for QT3000! OK?"; String pattern = "(\\D*)(\\d+)(.*)&q…
1.过滤特殊字符 package com.sheepmu.text; /* * @author sheepmu */ public class HWCompetition { public static void main(String[] args){ String s="a%&a^b}b*[cc]#d{d\"ee/ff\\gg"; //!!!!! \"是为了在字符串中转义"; \\ 只是为了在字符串中转义\ System.out.println…
/** * 正则提前字符串中的IP地址 * @param ipString * @return */ public static List<String> getIps(String ipString){ String regEx="((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"; List<String> ips = new ArrayList<Strin…
/** * 得到网页中图片的地址 */ public static Set<String> getImgStr(String htmlStr) { Set<String> pics = new HashSet<>(); String img = ""; Pattern p_image; Matcher m_image; // String regEx_img = "<img.*src=(.*?)[^>]*?>";…
public static Set<String> getImgStr(String htmlStr) { Set<String> pics = new HashSet<>(); String img = ""; Pattern p_image; Matcher m_image; // String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址 String reg…