regex - python finding multiple occurrences between 2 delimiter -
i'm trying find multiply occurrences between 2 delimiters using regex. unfortunately can't figure out how. 2 delimiters ' , ':
import re string = "'lightoff' 'lighton':,'lightoff' 'ovenoff' 'ovenon': none 'radioon': 'radiooff'" print string print 'newstring', re.findall("^'(.*?)':", string)
i first match
'lighton'
what want 3 substrings between ' , ':
'lighton' 'ovenon' 'radioon'
do not use anchor. ^
, $
anchors in regex pattern. also, when match between 2 '
, it'll return string 'word1' 'word2':
output, instead of 'word2':
. try match between 2 '
isn't character '
itself.
re.findall("'([^']+)':", string)
will work.
Comments
Post a Comment