php5与mysql5 web 开发技术详解-5 正则表达式
正则表达式(Regular Expression) 是查找和替换字符串模式的简洁和灵活的表示法。
重要性不再赘述,理解起来不算难,但若没有一定的实践,做到灵活应用还是不容易的。
在php中,分为 POSIX和PCRE两种规格的正则表达式。
先简单罗列出主要内容,以后再增加说明和实例。
一、POSIX (Portable Operating System Implementation for Unix),意为Unix可移植操作系统实现接口。
1、^ 和$ 定位符
2、量词或限定词
*
+
?
{n}
{n,}
{n,m}
3、方括号表达式
[aAeEiIoOuU] 所有元音字符的字符簇
[0-9] [a-z]
4、预定义字符簇 (内置的通用字符簇,指定字符的处理范围)
[[:alpha:]] 大小写字母,同[a-zA-Z]
[[:digit:]] 数字,同[0-9]
[[:alnum:]] 大小写字母和数字,同[a-zA-Z0-9]
[[:cntrl:]] 控制字符,包括Tab,退格或反斜线
[[:space:]] 任何白字符,包括空格、Tab、换行、换页和回车
......
不一一列举
5、正则表达式函数
ereg(条件,)
eregi() 不区分大小写
ereg_replace() : ereg()的基础上增加了字符替换功能
eregi_replace()
split() 针对字符串中的分隔符对串分割成数组形式
spliti()
sql_regcase()
6 、POSIX 子模式
二、PCRE(Perl Compatible Regular Expression)
1、字符簇
\\b
\\d
\\s
\\t
\\w
2、匹配
表达式的开始和结束处 使用分隔符 / ,最后一个分隔符/后,可添加修饰符
I ,M ,S,X,U,DU
还可以使用各种元字符,类似 POSIX的定位符和字符簇的组合
\A ,\b,\B,\d,\D,\s,\S,[],(),^,$,. ,\, \w ,\W
3、函数www.2cto.com
preg_match() :
例:preg_match('/^[[:alnum]]{4,8}$/', $username)
preg_match_all()
preg_quote() : 加转意字符
preg_split() :
preg_grep()
preg_replace() :替换
preg_replace_callback()

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools
