-1
import re

text = '"dimensionsDisplay" : ["Size","Color"], '
r = '"dimensionsDisplay" :(.*)?,'
s = re.search(r,text)
print s.group(1)

the output is :

' ["Size","Color"]'

Although it is the answer what I want , but I think it's should be:

' ["Size",'

I am puzzled about this. Is there anybody tell my why ?

olivetree123
  • 173
  • 3
  • 13

1 Answers1

0
r = '"dimensionsDisplay" :(.*?),'

You need to make your quantifier non greedy.? after (.*) makes it optional.But it will consume till the last , as it is greedy

vks
  • 67,027
  • 10
  • 91
  • 124