Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带有运行时输入和一些异常情况的正则表达式模式和匹配器_Java_Regex - Fatal编程技术网

Java 带有运行时输入和一些异常情况的正则表达式模式和匹配器

Java 带有运行时输入和一些异常情况的正则表达式模式和匹配器,java,regex,Java,Regex,在java文件中,我阅读了jsp文件,并试图通过使用下面的正则表达式找出所使用的css类的数量,“class=”及其值 Pattern p = Pattern.compile("class=\"([^\"]*)\""); Set set = new HashSet(); Iterator iterator; while ((strLine = br.readLine()) != null) { Matcher m = p.matcher(strLine); } while (m.find

在java文件中,我阅读了jsp文件,并试图通过使用下面的正则表达式找出所使用的css类的数量,“class=”及其值

Pattern p = Pattern.compile("class=\"([^\"]*)\"");
Set set = new HashSet();
Iterator iterator;
while ((strLine = br.readLine()) != null)
{
    Matcher m = p.matcher(strLine);
}
while (m.find())
{
    String classValue = m.group(1);
    set.add(classValue);
}
它给我的类名表示jsp内容class=“List”或class=“listItem”

输出如下所示。如果我的JSP内容

  • 然后它会显示com.metaparadigm.jsonrpc.JSONRPCBridge,这是我不想要的
  • “>在这里,它将给我
    output=“问题”
    根据你的加密描述,假设我已经正确破译了

    在我看来,您的jsp页面包含以下行

    <img src="a.jpeg" class="<%=w_canEdit?"IconSpacing":"IconDisable"%>"/>
    

    回答 简短答复:

    你不能用正则表达式

    长答覆:

    您不能使用regex来执行此操作,即使使用regex,您可能可以使用以下模式将其解析为
    类似于for ex

    Pattern p = Pattern.compile("class=\"(<%=(.(?<!%>\"))*)\"");
    // [<%=w_canEdit?"IconSpacing":"IconDisable"%>]
    

    Pattern p=Pattern.compile(“class=\”(这很难阅读。请重新格式化您的问题;粘贴源代码,突出显示源代码,然后按Ctrl-K将其格式化。我试图改进您的帖子,但我不知道最后一段想告诉我什么。请改进此段落。如果您单击编辑链接,您将在页面右侧找到有关格式化的帮助。)窗户。
    
    Input:
    <img src="a.jpeg" class="<%=w_canEdit?"IconSpacing":"IconDisable"%>"/>
    Result:
    [<%=w_canEdit?]
    
    [IconSpacing,IconDisable]
    
    Pattern p = Pattern.compile("class=\"(<%=(.(?<!%>\"))*)\"");
    // [<%=w_canEdit?"IconSpacing":"IconDisable"%>]