I am trying to learn how to write a RegEx but it seems all my searches lead to unclear information. So my question is two fold.
- Does anyone have a good source on how a newbie could learn to write RegExs?
- How could I write a RegEx that breaks the string 1y 311d 16h 42m into variables?
I'm looking to take the above text string and break it into something like:
$duration[years] = 1;
$duration[days] = 311;
$duration[hours] = 16;
$duration[minutes] = 42;
Please note the total digits might may not always be the same for example it could be two digit days. Something like. 25d or some could be omitted. I might just get days and hours. Lastly the order might change. Perhaps it is written days then years etc.
I know I could do this easily with an explode function and strpos, but I really want to learn Regex so I am using this as an example as I understand they can be very powerful for things like this.