相关文章推荐
深情的砖头  ·  JIRA之筛选器 - 知乎·  3 年前    · 
风流的消防车  ·  hyperledger fabric - ...·  3 年前    · 
淡定的小刀  ·  Changing the string ...·  3 年前    · 
  public void testRegex() {
        String msg = "Rect(x1=\"0\" y1=\"0\" x2=\"416\" y2=\"416\")Rect(x1=\"1\" y1=\"2\" x2=\"413\" y2=\"414\")";
        List<String> textList = new ArrayList<String>();
        Pattern pattern = Pattern.compile("(x1=\"[^\"]*\"\\s*y1=\"[^\"]*\"\\s*x2=\"[^\"]*\"\\s*y2=\"[^\"]*\")");
        Matcher matcher = pattern.matcher(msg);
        while (matcher.find()) {
            textList.add(matcher.group(1));
        for (String text : textList) {
            try {
                System.out.println(text);
                System.out.println(getValue(text, "x1"));
                System.out.println(getValue(text, "y1"));
                System.out.println(getValue(text, "x2"));
                System.out.println(getValue(text, "y2"));
            catch (Exception ex)
    public static String getValue(String source, String key) {
        if (isEmpty(source)) {
            return null;
        Pattern p = Pattern.compile("\\b" + key + "\\s*=\\s*\"([^\"]*)\"");
        Matcher m = p.matcher(source);
        if (m.find()) {
            return m.group(1);
        return null;
    public static boolean isEmpty(String str) {
        return str == null || str.length() == 0;


[^\"]表示不包含 引号,即 x1=“”这样的为空的字符串不会匹配

注意,匹配到的字符串并不含括号,如果想要匹配括号,那么应该这么写

Pattern pattern = Pattern.compile("(\\(x1=\"[^\"]*\"\\s*y1=\"[^\"]*\"\\s*x2=\"[^\"]*\"\\s*y2=\"[^\"]*\"\\))");

[^\"]表示不包含 引号,即 x1=“””这样的含多个引号不会匹配不会匹配

1.先把字符串进行匹配2.从字符串中得到想要的值 public void testRegex() { String msg = "Rect(x1=\"0\" y1=\"0\" x2=\"416\" y2=\"416\")Rect(x1=\"1\" y1=\"2\" x2=\"413\" y2=\"414\")"; List textList = new A
匹配中文字符 [\u4e00-\u9fa5] C# 代码如下: class Class1 { static void Main() { string s = “中文 chinese”; Regex regx = new Regex(“[\u4e00-\u9fa5]+”); Match m = regx.Match(s); Console.WriteLine(m.Groups[0].Value); // 中文 Console.ReadKey(); } } 匹配双字节字符(包括汉字) [^\x00-\xff] 您可能感兴趣的文章:PHP 正则表达
目录字符串替换正则表达式 本次实现的是在scala中,使用replaceAll实现正则匹配,其中正则匹配替换的key-value规则对应map中定义的key-value值。 上一篇文章讲的就是将用户传入的字符串参数按照格式分割并转换成map,感兴趣的可以去看看:《Scala实现函数将string分割为二维数组后,转化为map》 字符串替换 在scala中,replaceAll是基于规则表达式的替换,同时也支持字符(串)替换;比如,可以通过replaceAll("\d", “*”)把一个字符串所有的数字字符都
最近看到vue源码的模板解析,parse 中主要就是用正则去解析template然后生成ast抽象树。这则匹配用到最多的就是match。 match([string] | [RegExp]) 这里主要说正则表达式 1、返回值:Array/null 2、不使用g全局匹配时 var str='2019shanghai=nihao !!' str.match(/\w[i]/) 可以...
Python 的 re 模块(Regular Expression 正则表达式)提供各种正则表达式的匹配操作。在文本解析、复杂字符串分析和信息提取时是一个非常有用的工具,下面总结了 re 模块的常用方法。 二. 特殊字符 三. 反斜杠说明 五. 常用方法 六. 正则表达式函数里面的flags参数说明 flags定义包括: 示例1:具体使用说明
//1.正则             ///要被正则的字符串:[oid:25000][pos:1001][m:120.5][time:2014-02-02 12:00:00]             ///写一个正则表达式,要求:传来key值获取对应的value值.如:传来oid利用正在得到25000             string oid = CommRegEx.RegTest("[
报错:Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 48127