1

パターンマッチングを手伝ってください。j-文字列内の次の単語または次の単語に一致するパターンを作成したいc-(たとえば)

[j-test] is a [c-test]'s name with [foo] and [bar]

パターンは[j-test]and [c-test](括弧を含む) を見つける必要があります。

私がこれまでに試したことは何ですか?

String template = "[j-test] is a [c-test]'s name with [foo] and [bar]";
Pattern patt = Pattern.compile("\\[[*[j|c]\\-\\w\\-\\+\\d]+\\]");
Matcher m = patt.matcher(template);
while (m.find()) {
    System.out.println(m.group());
}

そして、その出力は次のようになります

[j-test]
[c-test]
[foo]
[bar]

これは間違っています。このスレッドでお時間をいただきありがとうございます。

4

1 に答える 1