Regular expression, also known as regular expression, is called Regular Expression in English. It is often abbreviated as regex, regexp or RE in the code. It is a concept in computer science. Regular tables are usually used to retrieve and replace text that matches a certain pattern (rule). A regular expression is a logical formula that operates on strings (including ordinary characters (for example, letters between a to z) and special characters (called "metacharacters")), which uses some predefined specific characters. , and the combination of these specific characters form a "rule string". This "rule string" is used to express a filtering logic for strings. A regular expression is a text pattern that describes one or more strings to match when searching for text.
The following is a collection of some commonly used regular expressions:
Only numbers can be entered: "^[0-9]*$"
Only n digits can be entered Numbers: "^\d{n}$"
Only numbers with at least n digits can be entered: "^\d{n,}$"
Only m ~ n digits can be entered Numbers: "^\d{m,n}$"
Only numbers starting with zero and non-zero can be entered: "^(0|[1-9][0-9]*)$"
You can only enter positive real numbers with two decimal places: "^[0-9]+(.[0-9]{2})?$"
You can only enter 1 ~Positive real numbers with 3 decimal places: "^[0-9]+(.[0-9]{1,3})?$"
Only non-zero positive integers can be entered: "^\ +?[1-9][0-9]*$"
Only non-zero negative integers can be entered: "^\-[1-9][0-9]*$"
Only characters with a length of 3 digits can be entered: "^.{3}$"
Only a string of 26 English letters can be entered: "^[A-Za-z]+$ "
Only a string consisting of 26 uppercase English letters can be entered: "^[A-Z]+$"
Only a string consisting of 26 lowercase English letters can be entered:" ^[a-z]+$"
You can only enter a string consisting of numbers and 26 English letters: "^[A-Za-z0-9]+$"
Only Enter a string consisting of numbers, 26 English letters or underscores: "^\w+$"
Verify user password: "^[a-zA-Z]\w{5,17}$" Correct Format bit: starts with a letter, has a length between 6 and 18, and can only contain characters, numbers and underscores
Verify whether it contains illegal characters ^(?:[\u4e00-\u9fa5]*\w*\ s*)+$
Only Chinese characters can be entered: "^[\u4e00-\u9fa5]{0,}$"
Verify email address: "^\w+([-+. ]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"
Verify InternetURL:"^http://([\ w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?$"
China Phone Number Verification
Matching Form Such as: 0511-4405222 or 021-87888822 or 021-44055520-555 or (0511)4405222
Regular expression "((d{3,4})|d{3,4}-)?d {7,8}(-d{3})*"
China Postal Code Verification
Matching format such as: 215421
Regular expression "d{6}"
Email verification
The matching form is: justali@justdn.com
Regular expression "w+([-+.]w+)*@w+([-. ]w+)*.w+([-.]w+)*"
ID card verification
Matching format such as: 15-digit or 18-digit ID card
Regular expression "d{18}|d{15}"
Commonly used number verification
Regular expression
"d{n}" n is the specified length
"d{n,m}" The length range from n to m
Illegal character verification
Match characters that exclude illegal characters such as:
Regular expression^(? :[\u4e00-\u9fa5]*\w*\s*)+$
Date verification
The matching format is: 20030718,030718
Range: 1900-- 2099
Regular expression ((((19){1}|(20){1})d{2})|d{2})[01]{1}d{1}[0 -3]{1}d{1}
<html> <head> <title>php正则表达式集锦实例</title> <script language="javascript" type="text/javascript"> function Button1_onclick(){ if(!test_hanzi(document.form1.Text1.value)){ alert("姓名只能是汉字"); return false; } return true; } //验证电子邮件 function test_email(strEmail){ var myReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/; if(myReg.test(strEmail)) return true; return false; } //只能输入数字 function test_shuzi(strshuzi){ var myReg =/^[0-9]*$/; if(myReg.test(strshuzi)) return true; return false; } //只能输入汉字 function test_hanzi(strhanzi){ var myReg =/^[\u4e00-\u9fa5]{0,}$/; if(myReg.test(strhanzi)) return true; return false; } </script> </head> <body> <form name="form1">姓名: <input id="Text1" name="Text1" type="text" /> <input name="按钮" type="button" id="Button1" onclick="return Button1_onclick()" value="button" language="javascript" /> </form> </body> </html>
The above is a collection of PHP expressions. I hope it is helpful to everyone and can be used in future work.
Related recommendations:
Detailed explanation of commonly used functions in php regular expressions
Instance analysis of php regular expressions
The ten most practical PHP regular expressions
Summary of regular expressions commonly used in PHP forms
Summary of commonly used regular expressions
The above is the detailed content of PHP regular expression collection. For more information, please follow other related articles on the PHP Chinese website!

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita

ToretrievedatafromaPHPsession,startthesessionwithsession_start()andaccessvariablesinthe$_SESSIONarray.Forexample:1)Startthesession:session_start().2)Retrievedata:$username=$_SESSION['username'];echo"Welcome,".$username;.Sessionsareserver-si

The steps to build an efficient shopping cart system using sessions include: 1) Understand the definition and function of the session. The session is a server-side storage mechanism used to maintain user status across requests; 2) Implement basic session management, such as adding products to the shopping cart; 3) Expand to advanced usage, supporting product quantity management and deletion; 4) Optimize performance and security, by persisting session data and using secure session identifiers.

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.


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

WebStorm Mac version
Useful JavaScript development tools

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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