这个正则表达式的输出是什么[重复]

问题描述 投票:-1回答:3

这个问题在这里已有答案:

这个正则表达式的输出是什么?

/\s+(\d+)\s+/

特别是/ \ s的含义是什么

regex
3个回答
0
投票

在你的正则表达式中,\s+按顺序匹配任意数量的空格,/d+按顺序匹配任意数量的数字。

\s\d分别匹配单个空格和单个数字,+使它分别匹配任意数量的连续空格和数字。


0
投票

你可以在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)

0
投票

https://regex101.com/

可能有用:D

\ s +(\ d +)\ s + /↵匹配字符↵字面(区分大小写)\ s +匹配任何空格字符(等于[\ r \ n \ t \ f \ v])+量词 - 匹配一次和无限次,尽可能多次,根据需要回馈(贪婪)第一捕获组(\ d +)\ d +匹配一个数字(等于[0-9])+量词 - 匹配一次和无限次,尽可能多次,根据需要回馈(贪婪)\ s +匹配任何空白字符(等于[\ r \ n \ t \ f \ v])+量词 - 匹配一次和无限次,尽可能多次,根据需要回馈

© www.soinside.com 2019 - 2024. All rights reserved.