tags:

views:

23

answers:

1

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}

+2  A: 

Add a pipe character to your regular expression:

"\\{([^\\}]+\\|[^\\}]+)\\}"
Mark Byers