【问题标题】:delimeter chararecter for a string consists of multiple regular expressions [closed]字符串的分隔符由多个正则表达式组成[关闭]
【发布时间】:2017-05-31 06:58:37
【问题描述】:

我需要将多个正则表达式存储在一个字符串中,然后将其检索并解析为原始正则表达式。我应该使用哪个分隔符来分隔这些正则表达式。

【问题讨论】:

  • 使用+ 绑定它们。使用() 组成不同的组。使用.group() 然后你可以访问你想要的每一个正则表达式。
  • 最好包含确切的示例来说明您的问题。没有它,很难说出你真正想要达到的目标。您很可能在谈论群组。

标签: java regex delimiter


【解决方案1】:

它可能看起来像下面的伪代码:

    String Regex="(regexOne)"+"(regexTwo)";
    Pattern pt=Pattern.compile(Regex);
    String line
    Matcher match=pt.matcher(line);
    
    if(match.find()){

       String matchedWithFirstRegex=match.group(1);
       String matchedWithSecondRegex=match.group(2);

     }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多