jQuery 按内容模式选择

jQuery Select By Content Pattern

本文关键字:模式 选择 jQuery      更新时间:2023-09-26

我需要选择

中具有与时间戳格式匹配的模式的所有段落

,例如:

<p>[22:48]</p>

<p>[22:48 - Subject Line]</p>

如何使用jQuery做到这一点?

更新

时间的有效格式:

1:24
24:59
1:24:01

时间格式无效:

24:70 [70 is not possible]
56:123 [last segment must have 2 digits from 00 - 59]
$('div p').filter(function(){
    return $(this).text().match(/'['d{2}:'d{2}.*']/);
});

现场演示

更新:

使用此regex

/^'['d*:?[0-6]?[0-9]:[0-6][0-9]'D?.*']$/