Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

Regular expression

How do I do a regular exp which will  contain:

hello in either lower or uppercase
or byebye in either lower or uppercase

both can have any prefix or suffix
5 Solutions
Like this?

What language are you using however?

Because you could simplify that down to:


And specify case insensitivty to the regex compiler.
Hmm.. Unless you mean that the entire string must be in either lower case or upper case, rather than potentially a mix of both?

In which case, you could do this:

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

something I picked up in perl earlier


Weiping DuSenior Web DeveloperCommented:
In Java:
Pattern ptrnForm = Pattern.compile("([.\\s]*?hello[.\\s]*?)|([.\\s]*?byebye[.\\s]*?)", Pattern.CASE_INSENSITIVE);

In Perl:
if( $str =~ /(hello)|(byebye)/i )
Anandhi KCommented:
Regex.IsMatch(Value,"(/.*?[hello|byebye]?/.*/i)", RegexOptions.IgnoreCase);

In regular expressions, a period can stand for any character. Using a period in a pattern is a way of requiring that "something" occurs here, without having to decide what. (because both can have any prefix or suffix)

the asterisk ("*") is any number of

question-mark ("?") means occurs exactly once

Advanced -- i - Case-insensitive match

Can avoid /i in case of using RegexOptions.IgnoreCase.
You don't need the () in
if( $str =~ /hello|byebye/i )
unless you also want to capture the match, which you can do with
if( $str =~ /(hello|byebye)/i )
But note that these would also match $str = "phellodendron"

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now