我有一个文本文件,我想从中解析字符串。关键是在完全相同的文件中,用单引号('
),双引号("
)或3x单引号('''
)括起来的字符串。到目前为止,我能得到的最好结果是使用此:
((?<=["])(.*?)(?=["]))|((?<=['])(.*?)(?=[']))
仅匹配单引号和双引号之间的单行字符串。请注意,文件中的字符串包含在每种引号中,可以是单行或多行,并且每种类型的字符串在文件中重复多次。
这是一个示例字符串:
<thisisthefirststring
'''- This is the first line of text
- This is the second line of text
- This is the third line of text
'''
>
<thisisanotheroption
"Just a string between quotes"
>
<thisisalsopossible
'Single quotes
Multiple lines.
With blank lines in between
'
>
<lineBreaksDoubleQoutes
"This is the first sentence here
After the first sentence, comes the blank line, and then the second one."
>
答案 0 :(得分:1)
答案 1 :(得分:0)
答案 2 :(得分:0)
使用记事本++,您可以使用:('''|'|")((?:(?!\1).)+)\1
说明:
('''|'|") : group 1, all types of quote
( : group 2
(?:(?!\1).)+ : any thing that is not the quote in group 1
) : end group 2
\1 : back reference to group 1 (i.e. same quote as the beginning)
答案 3 :(得分:0)
这可能对您有用。
^(\"([^\"\n\\]|\\[abfnrtv?\"'\\0-7]|\\x[0-9a-fA-F])*\"|'([^'\n\\]|\\[abfnrtv?\"'\\0-7]|\\x[0-9a-fA-F])*'|\"\"\"((?!\"\"\")[^\\]|\\[abfnrtv?\"'\\0-7]|\\x[0-9a-fA-F])*\"\"\")$
将三重双引号替换为三重单引号。在regex101.com上查看它的运行情况。