Questions about matching hours and minutes in this article

Source: Internet
Author: User
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 .
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.