私は静的になる特定の文字列のパターンを一致させようとします。以下は私のプログラムです:
package com.test.poc;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexTestPatternMatcher {
public static final String EXAMPLE_TEST = "http://localhost:8080/api/upload/form/{uploadType}/{uploadName}";
public static void main(String[] args) {
Pattern pattern = Pattern.compile("{\\w+}");
// In case you would like to ignore case sensitivity you could use this
// statement
// Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(EXAMPLE_TEST);
// Check all occurance
while (matcher.find()) {
System.out.print("Start index: " + matcher.start());
System.out.print(" End index: " + matcher.end() + " ");
System.out.println(matcher.group());
}
// Now create a new pattern and matcher to replace whitespace with tabs
Pattern replace = Pattern.compile("\\s+");
Matcher matcher2 = replace.matcher(EXAMPLE_TEST);
System.out.println(matcher2.replaceAll("\t"));
}
}
で利用可能な文字列を照合し{}
、それらを何らかの値に置き換えようとします。
しかし、それは私にこの例外を与えます:
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition
{\w+}
at java.util.regex.Pattern.error(Pattern.java:1713)
at java.util.regex.Pattern.closure(Pattern.java:2775)
at java.util.regex.Pattern.sequence(Pattern.java:1889)
at java.util.regex.Pattern.expr(Pattern.java:1752)
at java.util.regex.Pattern.compile(Pattern.java:1460)
at java.util.regex.Pattern.<init>(Pattern.java:1133)
at java.util.regex.Pattern.compile(Pattern.java:823)
at com.test.poc.RegexTestPatternMatcher.main(RegexTestPatternMatcher.java:9)
ここで何が問題になる可能性がありますか。ここで質問してすみません