ansible/ansible — pull request #8081 by danslimmon (2014-07-10 00:25:13+00:00)
Title: Fixed regex square-bracket bug

Regexes were being parsed like ordinary ansible host patterns, so square-bracket groups were getting interpolated wrongly. This PR fixes the issue and adds a regression test.

Steps to reproduce the bug:
```
# Create fake hostnames
$ echo "127.0.0.1 a1.localhost a2.localhost a3.localhost a4.localhost a5.localhost" | sudo tee -a /etc/hosts
$ for i in {1..5}; do echo "a${i}.localhost" >> /tmp/test_inventory

# Try to match 1, 2, and 5 with a regex
$ ./bin/ansible '~(a[12]|a5).localhost)' -i /tmp/test_inventory --list-hosts
Traceback (most recent call last):
File "./bin/ansible", line 221, in
(runner, results) = cli.run(options, args)
File "./bin/ansible", line 142, in run
hosts = inventory_manager.list_hosts(pattern)
File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 414, in list_hosts
result = [ h.name for h in self.get_hosts(pattern) ]
File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 160, in get_hosts
hosts = self._get_hosts(patterns)
File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 205, in _get_hosts
that = self.__get_hosts(p)
File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 226, in __get_hosts
hpat = self._hosts_in_unenumerated_pattern(name)
File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 310, in _hosts_in_unenumerated_pattern
if pattern == 'all' or self._match(group.name, pattern) or self._match(host.name, pattern):
File "/Library/Python/2.7/site-packages/ansible/inventory/__init__.py", line 146, in _match
return re.search(pattern_str[1:], str)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 142, in search
return _compile(pattern, flags).search(string)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 242, in _compile
raise error, v # invalid expression
sre_constants.error: unbalanced parenthesis
```