[英]Use JavaScript regex to capture all string values from VBA code
I want to use JavaScript regex to list all string values used in VBA code. 我想使用JavaScript正则表达式列出VBA代码中使用的所有字符串值。
Example: 例:
If cmd = "History Report" Then
Range("D2").Formula = "=TEXT(""" & createDate & """,""" & Replace(subtitleFormat, """", """""") & """)"
comment = "This task is completed!"
End If
The result will be: 结果将是:
1> "History Report"
2> "D2"
3> "=TEXT("""
4> ""","""
5> """"
6> """"""
7> """)"
8> "This task is completed!"
I'm so glad to have some better ideas to solve this problem. 我很高兴有一些更好的想法来解决这个问题。
""*[^"]*"*"
Try this.See demo. 试试看。看演示。
https://regex101.com/r/pG1kU1/19 https://regex101.com/r/pG1kU1/19
Edited: 编辑:
"(?:"{2})*[^"]*(?:"{2})*"
Try this.See demo. 试试看。看演示。
https://regex101.com/r/pG1kU1/23 https://regex101.com/r/pG1kU1/23
You need to account for double quotation marks inside string literals: 您需要在字符串文字中考虑双引号:
"((?:""|[^"])*)"
This will match all them. 这将匹配所有这些。 Capturing group 1 will hold the strings themselves. 捕获组1将自己持有琴弦。 If you want quotes to be part of your results, just use "(?:""|[^"])*"
. 如果您希望引号成为结果的一部分,只需使用"(?:""|[^"])*"
。
Another "unrolled" regex for this task: 此任务的另一个“展开”正则表达式 :
"((?:[^"]*(?:""[^"]*)*))"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.