PHP regular expression example

巴扎黑
Release: 2016-11-24 13:42:01
Original
1204 people have browsed it

The concept of regular expressions can be found in many places, so I won’t go into details here.
1. Is it related to text and characters?
The Chinese character range of Unicode is u4e00-u9fa5, the character corresponding to 4e00 is "一", and the Chinese character corresponding to 9fa5 is "龥", so the regular expression is like this:
1.1 matches all Chinese characters:

'/[一-龥]/u' or '/[/x{4e00}-/x{9fa5}]/u'

2. Is it related to the network and address?

2.1 Matching web page address:

"/https?:////([一-龥a-zA-Z///d/-]{1,30}/.){1,}([一-饥a-zA-Z]{2,9})(:/d{1,5})?([//|//]{1}[/w/./?=%]+) */u"

2.2 Matching email address:

'/[[:alnum:]._-]+@[[:alnum:]-]+/.([[:alnum:]-]+/. )*[[:alnum:]]+/'

3. Time and date related

3.1 Matching date

This is awesome, even leap years are included -_____-~ But I have not tested this.

"/(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1} [1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9] |[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02 -(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468] [048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)/"


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!