I tried re.match(r"[\'(.*?)\']", data)
But I got no luck
# input string value
"['WBAI@lalal']"
# expected output string
"WBAI@lalal"
I tried re.match(r"[\'(.*?)\']", data)
But I got no luck
# input string value
"['WBAI@lalal']"
# expected output string
"WBAI@lalal"
Your mistake is that you forgot to escape the brackets. The [ and ] are used to denote character classes in regex. re.match(r"\[\'(.*?)\'\]", data)
will get you what you're asking for, but this does not look like the best way to do whatever you're trying to do.
If you know that the string starts with ['
and ends with ']
, then you can just extract the content directly:
>>> s = "['WBAI@lalal']"
>>> s[2:-2]
'WBAI@lalal'