Question: I need a regex that will match 24 time format.

Eg
*2300* is valid
*2900* is not valid

I was using this:

```
_[0-2][0-3][0-5][0-9]_

```

But this doesn't allow \_1900\_etc\_

Answer: 
You need to decompose the `hours` part in two cases: from `00` to `19` and from `20` to `23`. This is done by using a `(pattern1|pattern2)` expression.

Hours: 00-23.

```
([01][0-9]|2[0-3])

```

Minutes: 00-59.

```
[0-5][0-9]

```

All together:

```
([01][0-9]|2[0-3])[0-5][0-9]

```
```
(?:[01]\d|2[0-3])[0-5]\d

```

1. `[01]\d` - hours from **00** to **19**
2. `2[0-3]` - hours from **20** to **23**
3. `[0-5]\d` - minutes from **00** to **59**