Link to home
Start Free TrialLog in
Avatar of Gabriel_Espinoza
Gabriel_EspinozaFlag for Chile

asked on

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!

Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

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
Avatar of Gabriel_Espinoza

ASKER

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?

SOLUTION
Avatar of mrjoltcola
mrjoltcola
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaufmed

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

Open in new window

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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you very much, it was my mistake cause I was using cuotes to pass the regex as parameter.

Thank you very much
NP. Glad to help  : )