【问题标题】:Get Integer between parenthesis using RegExp使用 RegExp 获取括号之间的整数
【发布时间】:2015-02-25 14:12:05
【问题描述】:

我正在尝试使用 regExp 来获取括号之间的值: 例如:

<td width=40><input type=\"button\" OnClick='FullScreen(1)' value=\" 1\" size=80></td>
<td width=(40)><input type=\"button\" OnClick='FullScreen(2)' value=\" 1\" size=80></td>
<td width=40><input type=\"button\" OnClick='FullScreen(3)' value=\" 1\" size=80></td>
<td width=40><input type=\"button\" OnClick='FullScreen(4)' value=\" 1\" size=80></td>

我想在本例中检索全屏的值 1、2、3 和 4

我试试这个正则表达式:

    Pattern p = Pattern.compile("\\((.*?)\\)");

    Matcher m = p.matcher(String);
    if(m.find()){
        System.out.println("val = " +m.group(1));
    }

但这会检索括号之间的所有值,我如何才能只从全屏字符串中获取值?

谢谢

【问题讨论】:

  • 所有 4 行都是同一个字符串的一部分,还是它们是单独的字符串?

标签: java regex


【解决方案1】:

还将FullScreen 前缀添加到您的正则表达式中。

Pattern p = Pattern.compile("FullScreen\\((.*?)\\)");
Matcher m = p.matcher(String);
if(m.find()){
    System.out.println("val = " +m.group(1));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-16
    相关资源
    最近更新 更多