JavaScript の正規表現エンジンと同様の結果を得るには non-capturing match group を使います。
Regular Expression Syntax
(?:...)
A non-capturing version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.
import re
test_data = '''
['Conflicting with version dependencies when running pip install',
"Hi everyone, Having issues with version dependencies when running `pip install` on docker.
However, when installing on my mac without docker and just virtualenv, works perfectly fine.
**Mac OS** - macOS Mojave v10.14. **Python Version** - v3.7.3 **Docker Compose Version** -
version 1.27.4, build 40524192 Here's the first error I got when running the docker-compose
up I tried to loosen the `six` package from `six==1.10.0` to `six>=1.2,<=1.15.0` And throws
a different error for requests package this time. Here's the error
'''
result = re.findall(r'[\w-]+(?:\.[\w-]+)*', test_data)
print(result)
## 結果(適宜改行を入れています)
['Conflicting', 'with', 'version', 'dependencies', 'when', 'running', 'pip',
'install', 'Hi', 'everyone', 'Having', 'issues', 'with', 'version', 'dependencies',
'when', 'running', 'pip', 'install', 'on', 'docker', 'However', 'when', 'installing',
'on', 'my', 'mac', 'without', 'docker', 'and', 'just', 'virtualenv', 'works',
'perfectly', 'fine', 'Mac', 'OS', '-', 'macOS', 'Mojave', 'v10.14', 'Python',
'Version', '-', 'v3.7.3', 'Docker', 'Compose', 'Version', '-', 'version', '1.27.4',
'build', '40524192', 'Here', 's', 'the', 'first', 'error', 'I', 'got', 'when',
'running', 'the', 'docker-compose', 'up', 'I', 'tried', 'to', 'loosen', 'the',
'six', 'package', 'from', 'six', '1.10.0', 'to', 'six', '1.2', '1.15.0', 'And',
'throws', 'a', 'different', 'error', 'for', 'requests', 'package', 'this', 'time',
'Here', 's', 'the', 'error']
その他に re.finditer を使う方法があります。
result = [m.group(0) for m in re.finditer(r'[\w-]+(\.[\w-]+)*', test_data)]