从这里copy了一个答案:
https://www.reddit.com/r/regex/comments/1288k8r/python_regex_to_match_all_strings_in_lua_code
他的正则是:
--[\S \t]*?\n|(\"(?:[^\"\\\n]|\\.|\\\n)*\"|\'(?:[^\'\\\n]|\\.|\\\n)*\'|\[(?P<raised>=*)\[[\w\W]*?\](?P=raised)\])
忽略了注释中的任何字符串。
匹配了三种形式,单引号字符串, 双引号字符串,用[[]]或者[=[]=]或者[==[]==]引起来的raw string
解释为:
--[\S \t]*?\n| Matches every comment line and "or" them out
\"(?:[^"\\\n]|\\.|\\\n)*\" --- Matches single line strings with double quotes
\'(?:[^'\\\n]|\\.|\\\n)*\' --- Matches single line strings with single quotes
\[(?P<raised>=*)\[[\w\W]*?\](?P=raised)\] --- Matches multiline string, (?P<raised>=*) and (?P=raised) will ensure matching the same level of the brackets, i.e. [==[ will only match ]==].
我的问题是:如何修改,使结果只匹配引号内的内容?不要带上单/双引号和[==[, ]==]
'nihao' -> nihao
"nihao" -> nihao
[[nihao]] -> nihao
[=[nihao]=] -> nihao
谢谢!
--
修改:allegro FROM 73.162.73.*
FROM 73.162.73.*