0

I tried re.match(r"[\'(.*?)\']", data)

But I got no luck

# input string value

"['WBAI@lalal']"

# expected output string

"WBAI@lalal"
user3675188
  • 7,271
  • 11
  • 40
  • 76
  • 1
    Sorry, I don't understand. Is that input a list with a string as element? Or is it that entire input a string. – idjaw Oct 05 '15 at 03:08

2 Answers2

0

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.

Zhewriix
  • 148
  • 10
0

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'
poke
  • 369,085
  • 72
  • 557
  • 602