tags:

views:

41

answers:

2

I'm looking for a regular expression for one of my particular requirement explained below. I believe that this may be very simple & basic for the regex experts.

A regular expression that matches one or more words in a line. Consider this line:

QRYNUMB0007 = SELECT EMPLOYEEID, FIRSTNAME, LASTNAME, EMAIL, CITY, STATE, COUNTRY FROM EMPLOYEE WHERE EMPLOYEEID = ?

In this case, for example, I want to find out whether the words I'm searching/looking for SELECT, FIRSTNAME and EMPLOYEE are available in the same line. Order of occurrence of the words in the line is not important in this case, but all the 3 words should be present in the same line.

+2  A: 

If you want to select any one of them

/select|firstname|employee/i

If you want to actually find all of them

/select/i && /firstname/i && /employee/i

And, depending on your language, things can be simpler, eg Python

STRING=mystring.lower()
if "select" in STRING and "firstname" in STRING and "employee" in STRING:
    print "...."
ghostdog74
@ghostdog74: Actually, am trying to use this regular expression from within Linux vi editor. I've another question here, where EOL (end-of-line) is specified in this expression?
Gnanam
+1  A: 
Frédéric Hamidi
@Frédéric: All the 3 words should be present and not any one of them.
Gnanam