REGEX of a HTML to get Hours

Hi all

I have the following string:
08:00<BR><DIV style="COLOR: red">17:00</DIV>

Open in new window


I can receive any hours indicated in the string.

Is there a way of getting an array of "hours" by using Regular Expressions?

I mean something like
var from = "08:00<BR><DIV style="COLOR: red">17:00</DIV>";
var to = from.match("fill_with_regular_expression");
// to[0] = "08:00"
// to[1] = "17:00"

Open in new window


in advance, many many thanks!

Gabriel_EspinozaAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
I tried all the expression you posted, none of them returned anything. I'm still getting a null.
Funny. Mine is not null.

<html>
	<head>
		<script type="text/javascript">
			var from = "08:00<BR><DIV style=\"COLOR: red\">17:00</DIV>";
			var to = from.match(/\d{1,2}:\d{1,2}/g);

			alert(to);
		</script>
	</head>
	<body>
	</body>
</html>

Open in new window

untitled.PNG
0
 
mrjoltcolaCommented:
You an use the global match modifier to return an array of matches.

>> var all = from.match("fill_with_regular_expression", "g");

Number of matches will be all.length


http://freewebdesigntutorials.com/javaScriptTutorials/jsRegularExpressionObject/regExpGlobalProperty.htm
0
 
Gabriel_EspinozaAuthor Commented:
Thank you for the fast reply,

I know I should use the "g" to list all matched elements. It was my bad for not pointing it out.

Now, could you help me with the regular expression?

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mrjoltcolaConnect With a Mentor Commented:
Something like this:

  (\d\d:\d\d)

or

  (\d{2}):(\d{2})
0
 
käµfm³d 👽Commented:

var to = from.match(/\d{1,2}:\d{1,2}/g)

Open in new window

0
 
Gabriel_EspinozaAuthor Commented:
thank you all for the fast reply.

I tried all the expression you posted, none of them returned anything. I'm still getting a null.

Any more ideas?
0
 
Gabriel_EspinozaAuthor Commented:
thank you very much, it was my mistake cause I was using cuotes to pass the regex as parameter.

Thank you very much
0
 
käµfm³d 👽Commented:
NP. Glad to help  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.