如何匹配两个冒号包围的字符串?使用Javascript [英] How to match string surrounded by two colons? Javascript
问题描述
我有以下刺痛
11:50:00
我如何匹配50分钟?
我尝试过:
var minutes = str.match(/ \:/ d {2} \:/ ); //匹配:50:,我怎么才能匹配数字?
编辑:
我已经找到了如何匹配这个正则表达式的分钟arg .match(/ \d {2}(?=:\d + $)/);
问题是,如果用户在它之前键入一个空格,这仍然会匹配,怎么能我阻止它?
)/);
问题是,如果用户在它之前键入一个空格,这仍然会匹配,我该怎样阻止它?
试试:
(?< = \d + :) \\ \\ n {2}(?=:\d +)
[edit]
愚蠢的语言Javascript - 这是正则表达式不支持lookbehind ...:叹气:
试试这个:
\d { 2}(=:\d + 块引用>
)它不那么强大,但它可以在JS中运行......
[/ edit]
I have the following sting "
11:50:00
how can I match minutes which is 50?
What I have tried:
var minutes = str.match(/\:/d{2}\:/);//matches ":50:", how can I match only the number?
Edited:
I have already found out how to match minutes with this regex arg.match(/\d{2}(?=:\d+$)/);
The problem is, if a user types a space before it, this still will match, how can I prevent it?
)/);
The problem is, if a user types a space before it, this still will match, how can I prevent it?
Try:
(?<=\d+:)\d{2}(?=:\d+)
[edit]
Stupid language Javascript - it's regular expressions don't support lookbehind... :sigh:
Try this:
\d{2}(?=:\d+
)It's not as robust, but it'll work in JS...
[/edit]
这篇关于如何匹配两个冒号包围的字符串?使用Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!