开发者

Rewrite this regexp to match only when other char is present

开发者 https://www.devze.com 2023-01-02 14:17 出处:网络
I have this regexp Pattern pattern = Pattern.compile(\"\\\\{([^\\\\}]+)\\\\}\"); to match {a1|a2|a3} and {a4} format

I have this regexp

Pattern pattern = Pattern.compile("\\{([^\\}]+)\\}");

to match {a1|a2|a3} and {a4} format

How can I rewrite the above line, to include those matches only when a pipe | is present, so to match {a1开发者_开发问答|a2|a3} and do not match on {a4}


Add a pipe character to your regular expression:

"\\{([^\\}]+\\|[^\\}]+)\\}"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号