简体   繁体   English

使用JavaScript正则表达式从VBA代码中捕获所有字符串值

[英]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 "(?:""|[^"])*" . 如果您希望引号成为结果的一部分,只需使用"(?:""|[^"])*"

See demo . 参见演示

Another "unrolled" regex for this task: 此任务的另一个“展开”正则表达式

"((?:[^"]*(?:""[^"]*)*))"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从JavaScript字符串获取/捕获所有variableNames和值 - Get/capture all variableNames and values from JavaScript string 正则表达式从字符串中获取所有 JavaScript 变量名称和值 - regex to get all JavaScript variable names and values from string 使用正则表达式从JavaScript中的字符串获取值数组 - Use regex to get array of values from string in javascript 如何使用JavaScript中的正则表达式从URL的参数捕获字符串 - How to capture a string from the parameters of a url using regex expressions in javascript 使用正则表达式从javascript中的字符串中提取值 - Using regex, extract values from a string in javascript Javascript Regex模式捕获-所有可能的组合 - Javascript Regex Pattern Capture - all possible combinations 正则表达式捕获以数字结尾的字符串中的所有数字 - Regex to capture all numbers in a string that ends with a number 正则表达式 JavaScript 捕获直到(之前)可选字符串 - Regex JavaScript capture till (before) optional string Javascript:使用正则表达式检查字符串是否仅包含另一个字符串的值? - Javascript: Use regex to check if a string has values only from another one? 使用正则表达式(javascript)检查字符串中的所有字母是否为辅音 - Use regex (javascript) to check if all letters in a string are consonants
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM