I have this string
hey {Bobby|Apple|Peter}, nice to meet you {David}
and this regex:
(\{(\w+)(\|(\w+))*)\}
the answer:
Bobby
Peter
David
However, it’s not getting “Apple”, how can I fix this to get it as well?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Repetition does not work for groups. Instead, try to iteratively use find on the string. Probably best to first filter out
{Bobby|Apple|Peter}, get the names from that, then find{David}and get the names from that. So that would be two finds, if you keep using regular expressions. Or onefind, then a split on|from the result.Regexp for the find:
\{(\w+(?:\|\w+)*)\}, then use group 1 (everything within the braces) and split the result.