在你的正则表达式中,\s+
按顺序匹配任意数量的空格,/d+
按顺序匹配任意数量的数字。
\s
和\d
分别匹配单个空格和单个数字,+
使它分别匹配任意数量的连续空格和数字。
你可以在regex101.com找到完整的解释。
/\s+(\d+)\s+/
\s+ matches any whitespace character (equal to [\r\n\t\f\v ])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
1st Capturing Group (\d+)
\d+ matches a digit (equal to [0-9])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
\s+ matches any whitespace character (equal to [\r\n\t\f\v ])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
可能有用:D
\ s +(\ d +)\ s + /↵匹配字符↵字面(区分大小写)\ s +匹配任何空格字符(等于[\ r \ n \ t \ f \ v])+量词 - 匹配一次和无限次,尽可能多次,根据需要回馈(贪婪)第一捕获组(\ d +)\ d +匹配一个数字(等于[0-9])+量词 - 匹配一次和无限次,尽可能多次,根据需要回馈(贪婪)\ s +匹配任何空白字符(等于[\ r \ n \ t \ f \ v])+量词 - 匹配一次和无限次,尽可能多次,根据需要回馈