有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java捕获字符串中属性的值?

在java中,文件内容是字符串。我需要捕获属性代码的值,即key.test.textkey.test.text1

 <input type="button" value="<s:message code="key.test.text"  />"
 <input type="button2" value='<s:message code="key.test.text1'  />"

=之前可以有空格,比如<input type="button" value = "<s:message code="key.test.text" />"

我不知道如何用正则表达式或字符串捕捉它


共 (1) 个答案

  1. # 1 楼答案

    根据你的最新需求,根据你的帖子和评论,下面是接受的答案

        Matcher matcher = Pattern.compile(
                "<s:message.*?code.*?=.*?[\"'](.*?)[\"'].*?>")
                .matcher(content);
    
        int count = 0;
        while (matcher.find()) {
            System.out.println(matcher.group(1));
    
            ++count;
        }