Regular expression

Posted on 2006-07-23
Last Modified: 2010-04-17
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
Question by:noam_dz
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 25

Accepted Solution

InteractiveMind earned 100 total points
ID: 17163088
Like this?

LVL 25

Expert Comment

ID: 17163094
What language are you using however?

Because you could simplify that down to:


And specify case insensitivty to the regex compiler.
LVL 25

Expert Comment

ID: 17163105
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:

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 65

Assisted Solution

rockiroads earned 100 total points
ID: 17163285
something I picked up in perl earlier



Assisted Solution

owenli27 earned 100 total points
ID: 17165221
In Java:
Pattern ptrnForm = Pattern.compile("([.\\s]*?hello[.\\s]*?)|([.\\s]*?byebye[.\\s]*?)", Pattern.CASE_INSENSITIVE);

In Perl:
if( $str =~ /(hello)|(byebye)/i )

Assisted Solution

by:Anandhi K
Anandhi K earned 100 total points
ID: 17165816
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.
LVL 84

Assisted Solution

ozo earned 100 total points
ID: 17165851
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"


Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Part One of the two-part Q&A series with MalwareTech.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question