Monday, November 22, 2010

Regular Expression question

Hello,

I have a regular expression question.

I am looping through a file looking for specific lines containing specific words.  Here is the basic logic.


Step 1. get line.

Step 2. does line contain word1.  Yes, goto step 3, No goto step 1.
Step 3. does line contain word2.  Yes, goto step 1, No goto step 4.
Step 4. print line.


For example, I have some lines:

1. word1 sometext

2. word1 sometext word2 sometext
3. word1 sometext
4. word1 sometext
5. word1 sometext word2 sometext
6. word1 sometext word2 sometext

All I want is lines 1, 3, and 4.

word1 sometext
word1 sometext
word1 sometext

I know there is a regular expression test to see if the line contains word1 but not word2, I just can not figure it out.

Any suggestions?

Thanks.

Jeff

No comments:

Post a Comment