Skip to content

Instantly share code, notes, and snippets.

@chrisshroba chrisshroba/regex
Last active Dec 16, 2016

What would you like to do?
A CLI for searching for a matching group and returning only that group (Rather than the entire matching line as grep does)
#!/usr/bin/env python
import re
from sys import argv
if len(argv)<3:
print("{} <string> <pattern>".format(argv[0]))
s = argv[1]
pattern = argv[2]
lines = s.split('\n')
for line in lines:
match =, line)
if match is not None:
result = match.groups()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.