{123{a,b}}一致させたい構造については、{123{and }}.
これは正規表現によって行われます:{(.*?){|}}
{a,b}BUT:今、同じ式を使用して実行し、一致させたいと思い{ます}。
したがって、私はどういうわけか2番目を{オプションにする必要があります。しかし、どのように?
http://gskinner.com/RegExr/を使用してその場でテストしています。
{123{a,b}}一致させたい構造については、{123{and }}.
これは正規表現によって行われます:{(.*?){|}}
{a,b}BUT:今、同じ式を使用して実行し、一致させたいと思い{ます}。
したがって、私はどういうわけか2番目を{オプションにする必要があります。しかし、どのように?
http://gskinner.com/RegExr/を使用してその場でテストしています。
You can use following regex:
(?:{.*?)?{|}}?
This makes all the content outside the inner braces optional.
(?:{.*?)?   // Contents before the opening inner brace '{' (Optional)
 {   
   |
 }
}?          // Last brace (Optional)
See demo on http://regexr.com?35t3r
たとえばどうですか?
/{(123{)?/
    このコードを使用してみてください:
Pattern pattern = Pattern.compile("\\{(.*\\{|[^\\}]*)");
        Matcher matcher1 = pattern.matcher("{123{a,b}}");
        Matcher matcher2 = pattern.matcher("{a,b}");
        while (matcher1.find()) {
            System.out.println(matcher1.group());
        }
        while (matcher2.find()) {
            System.out.println(matcher2.group());
        }
出力:
{123{
{a,b