There are several possible scenarios for a piece of text:
Used a
1 hours 43 minutes
Used a
1 hours
Used a
43 minutes
To achieve this is to match the time from the text, that is, the bold part
Now think of the regular expression is Preg_match ('/([0-9]+ hours] [0-9]+ minutes |[ 0-9]+ hours | [0-9]+ min]/is ', $txt, $matches)
Although can correctly match the desired result, but feel not concise, how can I improve?
Reply to discussion (solution)
Bold is only visual effect, separate to add and no effect
$s =<<< txt a text may appear in a few cases: 1 hours 43 minutes spent 1 hours with 43 minutes Txt;echo preg_replace ('/\d+ (Hours | minutes)/', ' $ A ',$s);
A text may appear in several cases: it took 1 hours and 43 minutes to spend 1 hours in 43 minutes .
I'm not trying to be bold, I'm trying to extract the text of the bold part. There are three cases, that is, hours and minutes, only hours, and minutes.
Bold is only visual effect, separate to add and no effect
$s =<<< txt a text may appear in a few cases: 1 hours 43 minutes spent 1 hours with 43 minutes Txt;echo preg_replace ('/\d+ (Hours | minutes)/', ' $ A ',$s);
A text may appear in several cases: it took 1 hours and 43 minutes to spend 1 hours in 43 minutes .