I want to change any
'None' (note single quotes) in a JSON file that contains both already.
type: None or type: 'None'
"s/[']?None[']?/'None'/g" but it doesn't seem to work.
Since you are changing all
'None', wouldn't it be easier to just use
str.replace with that json string? I'd run it in two procedures, first change
None, then change all
You could use a negative lookahead assertion
import re test = "type: None or 'None'" result = re.sub(r"None(?!')", r"'None'", test)
This will match
None as long as it is not directly followed by a
''None''He Shiming 2012-04-03 23:05