Reputation: 49
The problem I want to solve is the following: I have this string as input:
Hello World: [[DATA.[field]]] something else
the group I want to catch is:
DATA.[field]
The problem is that I want to catch whatever is inside "[[" and "]]".
What is the regex I should use in Java? Thanks
Upvotes: 0
Views: 103
Reputation: 9018
Try following regex:
(?<=\[\[).*?(?=\]\](\s|$))
Example:
String text = "Hello World: [[DATA.[field]]] something else";
Pattern regex = Pattern.compile("(?<=\\[\\[).*?(?=\\]\\](\\s|$))", Pattern.MULTILINE);
Matcher regexMatcher = regex.matcher(text);
if (regexMatcher.find()) {
System.out.println(regexMatcher.group());
}
From sample data string, it will print
DATA.[field]
Upvotes: 1