1

我在一些 javascript 代码上发现了这个,并想知道它匹配的是什么。

var i = /^tags: ?((?:.*, ?)*.*)$/m.exec(e.details);
4

1 回答 1

0
^ //start of the string
tags: //4 characters: "tags"
 ? //an optional space
((?:.* // 0 or more of any character except a newline
, ?) //a comma, then an optional space
* // all the stuff on the previous 2 lines, repeated 0 or more times
.*) //a capturing group of any character, repeated 0 or more times
$ //end of the string

基本上,用逗号分隔的标签列表。

这个正则表达式恰好接受任何以“tags:”开头的字符串

它试图捕获冒号之后的东西。(注意:我认为它不会像作者想要的那样做,因为.*它是贪婪的。)它在一组中捕获所有内容,而不是每组一个标签。

于 2013-08-26T23:47:39.733 回答