[英]Extracting strings in Python in either single or double quotes
我需要Python正則表達式的幫助來提取單引號或雙引號內的字符串。 我找到了一個解決方案,但正則表達式在C#中:
我需要解析這個字符串
tags = { 'one' : "two", "three", 'four' }
並返回數組項:
one
two
three
four
目前我有這個單引號:
quoted = re.findall(r"'(.*?)'", buffer, re.DOTALL)
>>> buffer="tags = { 'one' : \"two\", \"three\", 'four' }"
>>> re.findall(r"['\"](.*?)['\"]", buffer)
['one', 'two', 'three', 'four']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.