I'm coding a bash script for a code migration project which contains three stages: parse, processing and fix. It uses sed with regex to parse a file which contains directives as shown:

```
$(first_directive)    : [                        \
     $(dependency) ] \
     $(another_dependency)  \
# several commands here
$(second_directive)    :   \
     $(more_dependencies)
# more commands here  

```

Here the useful data for the process is only the strings $(first\_directive) and $(second\_directive), and I can recognize them because are the unique lines with colon after it. In order to parse these lines, I'm using in the script a command like this:

```
# Commands before
patterns=$(sed -nr "/\\$\(\w*\)\s*:/p" "${file}")
# More commands and processing after

```

That works fine, but I found that several lines are commented with # and I must discard them in the parse phase in order to avoid errors in the next stages of the process. Here is an example:

```
$(third_directive)    : [                        \
     $(dependency) ] \
# several commands here
#$(old_directive)    :   \  # I don't need this directive
#     $(old_dependencies)
### Commented code here
#  $(another_old_directive)   :   \ # I don't need this either  

```

So, I'm searching for sed parameters or different regex which allows me to excluded the commented lines, but I've not succeeded yet. It's possible do it with only a command?

The following are some regex that I tested:

```
(?:[^\#]\s*)\$\(\w*\)\s*
.*[^#]\$\([A-Za-z]*\)\s*:

```

**Edit:** The # may not be at beginning of the line. In some cases, there are blanks before.