簡體   English   中英

用單引號或雙引號在Python中提取字符串

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM