[英]Regex match a dynamic pattern
Hey guys i got stuck with this problem:嘿伙计们,我遇到了这个问题:
I have this pattern:我有这个模式:
(group1); (第一组); (group2);
(第 2 组); (group3);
(第 3 组); ... Actually i don't know how many groups the rows can have and i need to match all groups between
\s;\s
. ...实际上我不知道行可以有多少组,我需要匹配
\s;\s
之间的所有组。
I was thinking about a negative of pattern ^(?;\s;\s)
but it didn't work我在考虑模式的否定
^(?;\s;\s)
但它没有用
I would suggest doing a string split in this case, which also handles nicely the problem of not knowing how many groups you have, eg我建议在这种情况下进行字符串拆分,这也可以很好地处理不知道有多少组的问题,例如
var input = "group 1; group 2; group 3"; var groups = input.split(/\s*;\s*/); console.log(groups);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.