How to write a formal expression like this

Source: Internet
Author: User
How do you write a regular expression like this?
Mon-fri 8:00-23:00; Sat 10:00-23:00; Sun 10:00am-10:00pm;

Turn the above into Monday ~ Friday 8:00-23:00; Saturday 10:00-23:00; Sunday-10:00am;

$str = "Mon-fri 8:00-23:00; Sat 10:00-23:00; Sun 10:00am; "
$en =array ("Mon", "Fri", "Sat", "Sun");
$CN =array ("Monday", "Friday", "Saturday", "Sunday");
$str =str_replace ($en, $CN, $STR);

How to turn the English "-" into a ~, time between the non-replacement?
How to replace the space between English and digital?

Share to:


------Solution--------------------

$str = "Mon-fri 8:00-23:00; Sat 10:00-23:00; Sun 10:00am-10:00pm ";
$en =array ("Mon", "Fri", "Sat", "Sun");
$CN =array ("Monday", "Friday", "Saturday", "Sunday");
$str =str_replace ($en, $CN, $STR);
Echo $str;
$a [0]= '/([^\d]+) \-/';
$a [1]= '/\s (\d)/';
$b [0]= ' \1~ ';
$b [1]= ' \1 ';
$str =preg_replace ($a, $b, $str);
Echo $str;
  • 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.