About Regular Expressions in php

Source: Internet
Author: User

In our work, we often use regular expressions to match the data we want, and even replace the matched data with the data we need. It seems difficult to do this, but if you are familiar with regular expressions, it is not a dish.


Example 1: $ string is a string and $ patterns is defined as an index-based array,

 


The above example will output:

Kemo | addidas | that's it | haha | 11:40:43 | tengx | buyao

In the above example, we can express the values we need to replace in the form of an index array, and then replace them one by one. Is it very convenient?



Next let's take a look at it. We need to convert the date in the string to the current date or something we need.

Example 2:

 

The above example will output:

Kemo | addidas | that's it | haha | 12:07:55 | weobo | lail







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.