E
E
exaller2016-04-12 04:15:41
Regular Expressions
exaller, 2016-04-12 04:15:41

What is the correct way to write a regular expression if the group may not exist?

Example strings and desired result:

"11д 17ч 12м" - array(0 => 11, 1 => 17, 2 => 12)
"11д 12м"     - array(0 => 11, 1 => 0,  2 => 12)
"11д 17ч"     - array(0 => 11, 1 => 17, 2 => 0)
"17ч"         - array(0 => 0,  1 => 17, 2 => 0)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question