Solved

Regular expression

Posted on 2006-07-23
7
334 Views
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
0
Comment
Question by:noam_dz
7 Comments
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 100 total points
ID: 17163088
Like this?

([hH][eE][lL][lL][oO])|([bB][yY][eE][bB][yY][eE])
0
 
LVL 25

Expert Comment

by:InteractiveMind
ID: 17163094
What language are you using however?

Because you could simplify that down to:

(hello)|(byebye)

And specify case insensitivty to the regex compiler.
0
 
LVL 25

Expert Comment

by:InteractiveMind
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:

(hello)|(HELLO)|(byebye)|(BYEBYE)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 65

Assisted Solution

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

(h|H)|(e|E)|(l|L)|(l|L)|(o|O)


http://www.experts-exchange.com/Programming/Programming_Languages/Perl/Q_21921631.html


0
 
LVL 9

Assisted Solution

by:owenli27
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 )
0
 
LVL 7

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.
0
 
LVL 84

Assisted Solution

by:ozo
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"



0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
move one pixel 4 58
This code tracks birthdays 3 56
Definitions and default visual studio colors 5 58
Is doing tutor.com teaching in my situation advisable? 2 44
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

929 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now