Regular Expression Help

Hi there,

I have a line in a coded text from which the formtat is

DEF/AAA/AAA/AAA/AAA/AAA/AAA/AAA/AAA/AAA

where A equals a letter

but the fields after the DEF/ are optional. Which means the line could look like

DEF/AAA or
DEF/AAA/AAA etc etc  

I am trying to a find regular expression that will find all those lines that begin with DEF/ and in the rest (up to 9 fields) there is one of the following codes (BCD or DFG).

Is it possible to make this is one regular expression or I should use "OR" and do sth like

DEF/(BCD|DFG)||DEF/.../(BCD|DFG) etc etc

Thanks!

doing an "and" search in plain grep - it is sometimes faster for a one-off bit of code to use pipes - tuning the regex can take a while

grep '^DEF' filename | grep -e BCD -e DFG

This should work with sed, awk or egrep:

DEF.*[BCD||DFG].*

Regards

Thanks for your answer but the problem is that I have to use the regular expression in an xml so I can't use grep.

I thought he wanted old grep....

Works good! Thanks a lot! It matches regexp from tickle as well

I was mistaken. It doesn't work. If there is not BCD or DFG in the line and the line starts with DEF/ it matches is as well.

Eg. I tried this

DEF/AAA/AAA/AAA/AAA/AAA/AAA

and the DEF.*[BCD||DFG].* recognizes it as it matches the regexp

How I can correct this??

This is what I get with egrep:

$ cat file
DEF/AAA/AAA/AAA/AAA
DEF/ABC/BCD/AAA/ABC
DEF/AAA/AAA/AAA/AAA
DEF/AAA/TTT/AAA/AAA
DEF/AAA/AAA/AAA/DFG
$ egrep 'DEF.*[BDC||DFG].*' file
DEF/ABC/BCD/AAA/ABC
DEF/AAA/AAA/AAA/DFG
$

Regards

I found the problem. The problem was that the application I use, uses behind a strange TCL regexp tester which didn't accept the but only ( ). I don't know the reason but this was the problem.

Thanks for the help