-1

I am trying to get the values ​​that are in braces as below:

{{{{{{{{{{{{{{{{{{value1 here!}}}}}}}}}}}{value2 here!}}}}}}}}}{value3 here!}}}}}}

I would like you to be selected as a group:

{value1 here!} {value2 here!} {value3 here!}

I'm doing the expression on the site Regex101 and applying it to my Java project.

Pattern p = Pattern.compile("\\\\{.*\\\\}");
Matcher m = p.matcher("{{{{{{{{{{{{{{{{{{value1 here!}}}}}}}}}}}{value2 here!}}}}}}}}}{value3 here!}}}}}}");
if (m.find()){
    String value1 = m.group(1);
    String value2 = m.group(2);
    String value3 = m.group(3);
}

How can I solve this problem?

sYsTeM
  • 37
  • 3
  • 18
  • 3
    https://regex101.com/r/23sVIZ/5 – sshashank124 Jan 04 '20 at 18:22
  • 1
    `m.group(3)` suggests that you confuse *match* with *group*. Also your `.*}` will match everything it can, until last `}`.Maybe use `[^}]*}` instead. – Pshemo Jan 04 '20 at 18:25
  • My question has nothing to do with the above association. The one that is associated with mine addresses another path ¯\(°_o)/¯ – sYsTeM Jan 04 '20 at 22:54

1 Answers1

0

You just need your glob match to match on non-brace characters:

\{[^{}]*\}

Regex101


This is accomplished by using the construct [^...] for negated character classes which matches all characters except the ones specified within the [^ and ] delimiters

sshashank124
  • 31,495
  • 9
  • 67
  • 76