0

I need to select all paragraphs < p > within a < div > that have a pattern matching time stamps formatting like:

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

or

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

How can this be done with jQuery?

UPDATE

Valid formats for times:

1:24
24:59
1:24:01

Invalid formats for times:

24:70 [70 is not possible]
56:123 [last segment must have 2 digits from 00 - 59]
1
  • What about <p> aa [22:48]</p> ? Commented May 30, 2012 at 10:51

1 Answer 1

1
$('div p').filter(function(){
    return $(this).text().match(/\[\d{2}:\d{2}.*\]/);
});

Live DEMO

Update:

use this regex:

/^\[\d*:?[0-6]?[0-9]:[0-6][0-9]\D?.*\]$/
Sign up to request clarification or add additional context in comments.

3 Comments

the last segment of the time code must be 2 digits but any others do not have to be
@phirschybar. Can you show more examples of valid and invalid <p> ?
@phirschybar. I updated. Next time give the options in <p> ...</p> format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.