简体   繁体   中英

Regex match a dynamic pattern

Hey guys i got stuck with this problem:

I have this pattern:

(group1); (group2); (group3); ... Actually i don't know how many groups the rows can have and i need to match all groups between \s;\s .

I was thinking about a negative of pattern ^(?;\s;\s) but it didn't work

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);

Try this example

([^\s;]{3,})  // made use of negation approch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM