How do I write a regex, that works in wxRegEx, to match something this pseudo regex: *good|better|best* ?
I know about regex matching at the character level, i.e. *.[ch]pp, but how does it go as far as whole words go?
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.
This question is a good example of why you should always specify the flavor of regex you’re using. Most regex flavors provide a way to match word boundaries, and most of those use
\bfor that. According to this page, wxRegEx lets you choose one of three flavors: BRE, ERE, or ARE. Of those, only ARE supports word boundaries, and it uses\y, not\b. Assuming you specifywxRE_ADVANCEDwhen you compile it, this regex will match any string that contains one of the wordsgood,better, orbest:Judging by the examples you used, I think you may be confusing regexes with globs. For example,
*.[ch]is the glob you’d use to match file names ending with.cor.h; the regex for that would be\.[ch]$. There’s a good regex tutorial at the site I linked to earlier, but the difference I’m most concerned with is that a regex doesn’t have to describe the whole string like a glob does. That’s why I didn’t have to start the regex with.*, but I did have to add$to the end, to keep it from matching strings likefoo.csorbar.html.