Get the string within brackets in Python
How about: import re s = “alpha.Customer[cus_Y4o9qMEZAugtnW] …” m = re.search(r”\[([A-Za-z0-9_]+)\]”, s) print m.group(1) For me this prints: cus_Y4o9qMEZAugtnW Note that the call to re.search(…) finds the first match to the regular expression, so it doesn’t find the [card] unless you repeat the search a second time. Edit: The regular expression here is a python … Read more