Home Backend Development PHP Tutorial 几个比较有用的正则表达式_PHP

几个比较有用的正则表达式_PHP

Jun 01, 2016 pm 12:29 PM
lt match character it works Compare expression length

正则表达式

匹配中文字符的正则表达式: [\u4e00-\u9fa5]

匹配双字节字符(包括汉字在内):[^\x00-\xff]

应用:计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)

String.prototype.len=function(){return this.replace([^\x00-\xff]/g,"aa").length;}

匹配空行的正则表达式:\n[\s| ]*\r

匹配HTML标记的正则表达式:/.*|/

匹配首尾空格的正则表达式:(^\s*)|(\s*$)

验证jpg和GIF图片:^.{1,}\.((j|J)(p|P)(g|G)|(g|G)(i|I)(f|F))$

验证IP地址:

^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to enable nfc function on Xiaomi Mi 14 Pro? How to enable nfc function on Xiaomi Mi 14 Pro? Mar 19, 2024 pm 02:28 PM

How to enable nfc function on Xiaomi Mi 14 Pro?

How to use TikTok on Huawei Pocket2 remotely? How to use TikTok on Huawei Pocket2 remotely? Mar 18, 2024 pm 03:00 PM

How to use TikTok on Huawei Pocket2 remotely?

How to set line spacing in WPS Word to make the document neater How to set line spacing in WPS Word to make the document neater Mar 20, 2024 pm 04:30 PM

How to set line spacing in WPS Word to make the document neater

iPhone 16 Pro CAD drawings exposed, adding a second new button iPhone 16 Pro CAD drawings exposed, adding a second new button Mar 09, 2024 pm 09:07 PM

iPhone 16 Pro CAD drawings exposed, adding a second new button

The difference and comparative analysis between C language and PHP The difference and comparative analysis between C language and PHP Mar 20, 2024 am 08:54 AM

The difference and comparative analysis between C language and PHP

How to use Xiaomi Mi 14 Ultra AI smart image expansion? How to use Xiaomi Mi 14 Ultra AI smart image expansion? Mar 16, 2024 pm 12:37 PM

How to use Xiaomi Mi 14 Ultra AI smart image expansion?

TrendX Research Institute: Merlin Chain project analysis and ecological inventory TrendX Research Institute: Merlin Chain project analysis and ecological inventory Mar 24, 2024 am 09:01 AM

TrendX Research Institute: Merlin Chain project analysis and ecological inventory

Oracle Version Competition: Which Version Is Better for Your Needs? Oracle Version Competition: Which Version Is Better for Your Needs? Mar 07, 2024 pm 01:21 PM

Oracle Version Competition: Which Version Is Better for Your Needs?

See all articles