Question: For example, I have a filename `[foo] FooBar[!].bar`

How can I use regex to match `FooBar` but not `[foo]`, `[!]` or `.bar`

BTW, I'm using Python Regex, if that has any bearing.

Basically, I want to match anything that is not after a dot, or is not in brackets.

Answer: 
```
fileName = '[abc][def]Real Name[!].exe'
name = re.search('(\[[^]]*\])*([\w\s]+)', fileName).group(2)
print name

```

This should print 'Real Name'
You could replace it all:

```
>>> re.sub(r'\[.*?\]|\..*', '', '[foo] FooBar[!].bar')
    ' FooBar'

```