I\'m trying to grab any text outside of brackets with a regex.
Example string
Josie Smith [3996 COLLEGE AVENUE, SOMETOWN, MD
If there are never nested brackets:
([^[\]]+)(?:$|\[)
Example:
>>> import re
>>> s = 'Josie Smith [3996 COLLEGE AVENUE, SOMETOWN, MD 21003]Mugsy Dog Smith [2560 OAK ST, GLENMEADE, WI 14098]'
>>> re.findall(r'([^[\]]+)(?:$|\[)', s)
['Josie Smith ', 'Mugsy Dog Smith ']
Explanation:
([^[\]]+) # match one or more characters that are not '[' or ']' and place in group 1
(?:$|\[) # match either a '[' or at the end of the string, do not capture