Given a string like this:
"7 years 11 months 3 weeks"
I need to parse it out so that in PHP, the preg_split function returns an array that contains:
0 => "7 years"
1 => "11 months"
2 => "3 weeks"
The age string can also contain zeros like "0 years 1 month 0 weeks".
The regex string I have right now only seems to split between years and months:
(?!\d+)(?:\s)(?!\D+)
and that is throwing off the calculations.
I'm not very familiar with regex and I can't figure out what I'm doing wrong.
source https://stackoverflow.com/questions/71710244/regex-to-split-years-months-and-weeks
No comments:
Post a Comment