


What are atoms in regular expressions in PHP? What content does it consist of? (with code)
The previous article introduced you to "What is the delimiter of a regular expression? What do we need to pay attention to? (Attached code) 》, this article continues to introduce to you what are atoms in regular expressions in PHP? What content does it consist of? (With code)
##Atoms in regular expressions
What is an atom:
The smallest unit that makes up a regular expression is an atom.What are the contents of atoms:
- Normal letters are atoms, and all visible characters are atoms.
- Most invisible characters are also atoms, such as: space, \n, \r, \t
- \d represents the number 8- Any character between 9. [e-中
- \D means matching any one character except numbers 0-9
- \s means matching blank characters , including any character among spaces, \n, \r, \t
- \S means matching any one character except whitespace characters
- T \w means matching any character among numbers, uppercase and lowercase letters, and underscores
- W means matching any character except numbers, uppercase and lowercase letters, and underscores.
- []Atom list
- means selecting an atom from the specified characters
- [ 5-9] represents 5, 6, 7, 8, 9 consecutive characters. It is allowed to be abbreviated to the starting character and ending character
- [^ ] Exclusion list
- [^ abc] means that all characters except abc can be used.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>表单页面</title> </head> <body> <form action= "2.php"method= "post"> <input type="text" name="str" id=""/> <input type="submit" value="匹配" > </form> </body> </html>Then we enter a ( submit) for matching. After matching, it will be passed to the page we just created. At this time, we are creating a new page. In the new page, do we need to match? What we need to do is those atoms whose content is our regular. Before matching, we first define a string to receive, and then we define a regular expression, because if the regular expression wants to match, it must cooperate with the function, so we have to call the regular matching function (preg_match( )), at the beginning we passed in two parameters, one is the regular expression we defined, and the second is the string we want to match. In fact, we can pass the third parameter which is the matched result (match ), if it matches, it returns 1, if it does not match, it returns 0; so we output the matching result, call the if statement, and judge the output result The code is as follows:
<?php //进行匹配 $str = $_POST['str']; $pattern = '//' ; //调用正则匹配函数 $result = preg_match($pattern , $str , $match); echo ' 匹配结果为: '.$result; echo '<hr/>' ; if ( $result){ echo '<font color="pink" size="5 ">匹配成功</font>'; }else{ echo '<font color="red">匹配失败</font>'; } var_dump($match); ?>The code result is as follows:
PHP Video Tutorial"
The above is the detailed content of What are atoms in regular expressions in PHP? What content does it consist of? (with code). For more information, please follow other related articles on the PHP Chinese website!

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

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

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

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

SublimeText3 English version
Recommended: Win version, supports code prompts!
