Hello,
There is such a code

<script> var str = 'Подъем в 06:50. Душ в 7-10. Зарядка в 7:30'; var re = /\d\d[-:]\d\d/g; alert(str.match(re)); </script> 

In IE9, an alert displays only the first match - 06:50. How to display all matches?

  • one
    @Irinkes Button editor 101010 formats the code. - Nicolas Chabanovsky

2 answers 2

Try this:

 var sample = 'Подъем в 06:50. Душ в 07-10. Зарядка в 07:30'; var re = /\d\d[-:]\d\d/g; var match = null; while (match = re.exec(sample)){ alert(match); } 

Note that in your line 7-10 and 7:30 do not have a zero at the beginning.

  • zeros! thanks, then the code works without a loop - Irinkes

You can put \d{1,2} instead of \d\d

 <script> var str = 'Подъем в 06:50. Душ в 7-10. Зарядка в 7:30'; var re = /\d{1,2}[-:]\d\d/g; alert(str.match(re)); </script> 
  • Cool! Thank you! - Irinkes
  • Then, too: / (?: 0 | [01] \ d | 2 [0-3]) [-:] (?: 0 | [0-5] \ d) / gm - timka_s