Rewrite this regexp to match only when other char is present
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:
"\\{([^\\}]+\\|[^\\}]+)\\}"
精彩评论