如果后跟某个字符串则捕获子字符串
Capturing substrings if followed by certain string
我正在尝试捕获引号之间的消息名称。它可以格式化为
("AddMessage",function(e){...})
或即
("AddMessage","RemoveMessage",function(e){...})
我正在尝试使用正则表达式捕获消息的名称,但是在我尝试的正则表达式上
\("(?<name>\w+Message)"(,"(\w+Message)")*,function\([\w,]*\){.*?}\)
Regex101 tells me 使组递归以捕获多个消息的名称。
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data.
我真的搞不懂,谁能帮帮我?
您必须将重复的部分捕获到封闭的捕获组中。
在重复的部分周围添加命名捕获组,并使用"grouping only"(不捕获捕获组)用于内部:
\("(?<name>\w+Message)",?(?<messages>(?:"\w+Message",?)*),function\([\w,]*\){.*?}\)
我正在尝试捕获引号之间的消息名称。它可以格式化为
("AddMessage",function(e){...})
或即
("AddMessage","RemoveMessage",function(e){...})
我正在尝试使用正则表达式捕获消息的名称,但是在我尝试的正则表达式上
\("(?<name>\w+Message)"(,"(\w+Message)")*,function\([\w,]*\){.*?}\)
Regex101 tells me 使组递归以捕获多个消息的名称。
A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data.
我真的搞不懂,谁能帮帮我?
您必须将重复的部分捕获到封闭的捕获组中。
在重复的部分周围添加命名捕获组,并使用"grouping only"(不捕获捕获组)用于内部:
\("(?<name>\w+Message)",?(?<messages>(?:"\w+Message",?)*),function\([\w,]*\){.*?}\)