Now I will bring you a regular expression (grammar recommendation). Let me share it with you now and give it as a reference for everyone.
Construction summary of regular expression
Construction matches
Character
x Character x
\\ Backslash character
\0n Character n with octal value 0 (0 \0nn Character nn with octal value 0 (0 \0mnn character mnn with octal value 0 (0 \xhh with hexadecimal value Character hh with value 0x
\uhhhh Character hhhh with hexadecimal value 0x
\t Tab character ('\u0009')
\n Newline (newline) character ('\u000A ')
\r Carriage return character ('\u000D')
\f Form feed character ('\u000C')
\a Alarm (bell) character ('\u0007')
\ e escape character ('\u001B')
\cx Control character corresponding to x
Character class
[abc] a, b or c ( Simple class)
[^abc] Any character except a, b or c (negative)
[a-zA-Z] a to z or A to Z, inclusive (range)
[a-d[m-p]] a to d or m to p: [a-dm-p] (union)
[a-z&&[def]] d, e or f (intersection)
[ a-z&&[^bc]] a to z, except b and c: [ad-z] (minus)
[a-z&&[^m-p]] a to z, not m to p: [a -lq-z] (minus)
Predefined character classes
. Any character (which may or may not match line terminators)
\ d Numbers: [0-9]
\D Non-numbers: [^0-9]
\s White space characters: [ \t\n\x0B\f\r]
\S Non-white space characters :[^\s]
\w Word characters: [a-zA-Z_0-9]
\W Non-word characters: [^\w]
POSIX character class (only US- ASCII)
\p{Lower} Lowercase alphabetic characters: [a-z]
\p{Upper} Uppercase alphabetic characters: [A-Z]
\p{ASCII} All ASCII: [\x00-\x7F]
\p{Alpha} Alphabetic characters: [\p{Lower}\p{Upper}]
\p{Digit} Decimal digits: [0-9]
\p{Alnum} Alphanumeric characters :[\p{Alpha}\p{Digit}]
\p{Punct} Punctuation: !"#$%&'()* ,-./:;?@[\] ^_`{|}~
\p{Graph} Visible characters: [\p{Alnum}\p{Punct}]
\p{Print} Printable characters: [\p{Graph}\x20 ]
\p{Blank} Space or tab character: [ \t]
\p{Cntrl} Control character: [\x00-\x1F\x7F]
\p{XDigit} Hexadecimal System digits: [0-9a-fA-F]
\p{Space} Blank characters: [ \t\n\x0B\f\r]
java.lang.Character class (simple java character type)
\p{javaLowerCase} is equivalent to java.lang.Character.isLowerCase()
\p{javaUpperCase} is equivalent to java.lang.Character.isUpperCase()
\p{ javaWhitespace} Equivalent to java.lang.Character.isWhitespace()
\p{javaMirrored} Equivalent to java.lang.Character.isMirrored()
Classes for Unicode blocks and categories
\p{InGreek} Characters in Greek block (simple block)
\p{Lu} Uppercase letters (simple category)
\p{Sc} Currency symbols
\P{InGreek} All characters , except in Greek blocks (negation)
[\p{L}&&[^\p{Lu}]] All letters, except uppercase letters (minus)
Boundary matcher
^ Beginning of line
$ End of line
\b Word boundary
\B Non-word boundary
\A Beginning of input
\ G The end of the previous match
\Z The end of the input, only used for the last terminator (if any)
\z The end of the input
Greedy quantifier
X? Times
X{n,} X, at least n times
X{n,m} #X?? #X{n,}? X, at least n times
X{n,m}?
X? #X{n,} X, at least n times
X{n,m} X, at least n times, but not more than m times
Logical operator
XY X followed by Y
X|Y X or Y
(X) #\n Any matching nth capture group
Quotes
\Q Nothing, but quotes all characters up to \E \E Nothing, but ends with \Q Starting reference
Special construction (non-capturing)
(?:X) X, as a non-capturing group
(?idmsux-idmsux) Nothing, but will match the flag idms u The non-capturing group of the given flag i d m s u x on - off
(?=X) X) X, through a zero-width positive lookbehind
(?
Backslash, escape and quote
The backslash character ('\') is used for quote escape constructs, as shown in the table above defined, but also used to refer to other characters that will be interpreted as unescaped constructs. Therefore, the expression \\ matches a single backslash, and \{ matches an opening parenthesis. It is an error to use backslashes before any alphabetic characters that do not represent an escape construct; they are reserved for future extensions to the regular expression language. A backslash can be used before a non-alphabetic character, regardless of whether the character is part of an unescape construct. As required by the Java Language Specification, backslashes in strings in Java source code are interpreted as Unicode escapes or other character escapes. Therefore, you must use two backslashes in the string literal to indicate that the regular expression is protected from being interpreted by the Java bytecode compiler. For example, when interpreted as a regular expression, the string literal "\b" matches a single backspace character, while "\\b" matches a word boundary. The string literal "\(hello\)" is illegal and will cause a compile-time error; to match the string (hello), the string literal "\\(hello\\)" must be used.
Character ClassesCharacter classes can appear within other character classes and can contain the union operator (implicit) and the intersection operator (&&). The union operator represents a class that contains all characters in at least one of its operand classes. The intersection operator represents a class that contains all characters that are in both of its operand classes.
The precedence of character class operators is as follows, arranged from highest to lowest:
1 Literal value escaping \x
2 Grouping [...]3 Range a-z 4 Union [a-e][i-u] 5 Intersection [a-z&&[aeiou]]
Note that different sets of metacharacters are actually is inside the character class, not outside the character class. For example, the regular expression . loses its special meaning within a character class, while the expression - becomes a range forming metacharacters.
Line terminator
Line terminator is a sequence of one or two characters that marks the end of a line for a sequence of input characters. The following codes are recognized as line terminators: New line (line feed) character ('\n'), Carriage return character ("\r\n") followed by a new line character, A single carriage return ('\r'),
Next line character ('\u0085'),Line separator ('\u2028') or
Paragraph separator ('\ u2029). If UNIX_LINES mode is activated, the newline character is the only recognized line terminator.
If the DOTALL flag is not specified, the regular expression . can match any character (except line terminators).
By default, the regular expressions ^ and $ ignore line terminators and only match the beginning and end of the entire input sequence, respectively. If MULTILINE mode is activated, ^ matching occurs at the beginning of the input and after the line terminator (at the end of the input). When in MULTILINE mode, $ matches only before a line terminator or at the end of the input sequence.
Groups and Captures
Capturing groups can be numbered by counting their opening brackets from left to right. For example, in the expression ((A)(B(C))), there are four such groups: 1 ((A)(B(C))) 2 \A 3 (B(C))
4 (C) Group zero always represents the entire expression.
The capturing groups are named this way because in the match, every subsequence of the input sequence that matches these groups is saved. The captured subsequence can later be used in an expression via a Back reference, or can be obtained from the matcher after the matching operation has completed.
The capture input associated with a group is always the subsequence that most recently matched the group. If a group is calculated again due to quantization, its previously captured value (if any) will be retained when the second calculation fails. For example, comparing the string "aba" with the expression (a(b)?) match, sets the second group to "b". At the beginning of each match, all captured input is discarded.
A group starting with (?) is a pure non-capturing group, which does not capture text and does not count against the group total.
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
related articles:
What are the common scenarios in which closures can be exploited in JS? (Picture and text tutorial)
How to copy an object in js? (Picture and text tutorial)
Example of using js to implement a message board (code provided)
The above is the detailed content of Regular expressions (grammar). For more information, please follow other related articles on the PHP Chinese website!

提到API开发,你可能会想到DjangoRESTFramework,Flask,FastAPI,没错,它们完全可以用来编写API,不过,今天分享的这个框架可以让你更快把现有的函数转化为API,它就是Sanic。Sanic简介Sanic[1],是Python3.7+Web服务器和Web框架,旨在提高性能。它允许使用Python3.5中添加的async/await语法,这可以有效避免阻塞从而达到提升响应速度的目的。Sanic致力于提供一种简单且快速,集创建和启动于一体的方法

随着PHP8.0的发布,新增了一种类型别名语法,使得使用自定义的类型变得更加容易。在本文中,我们将深入了解这种新的语法,以及它对开发人员的影响。什么是类型别名?在PHP中,类型别名本质上是一个变量,它引用另一个类型的名称。这个变量可以像其他类型一样使用,并在代码中的任何地方声明。这种语法的主要作用是为常用的类型定义自定义别名,使得代码更加易于阅读和理解。

Go语言与JS的联系与区别Go语言(也称为Golang)和JavaScript(JS)都是当前流行的编程语言,它们在某些方面有联系,在其他方面又有明显的区别。本篇文章将探讨Go语言与JavaScript之间的联系与区别,同时提供具体的代码示例来帮助读者更好地理解这两种编程语言。联系:都是跨平台的Go语言和JavaScript都是跨平台的,可以在不同的操作系统

Python作为一种高级编程语言,易于学习和使用。一旦需要编写Python程序时,无法避免地遇到语法错误,表达式语法错误是常见的一种。在本文中,我们将讨论如何解决Python的表达式语法错误。表达式语法错误是Python中最常见的错误之一,它通常是由于错误的使用语法或缺少必要组件而导致的。在Python中,表达式通常由数字、字符串、变量和运算符组成。最常见的

PHP是一种广泛应用于Web开发的服务器端脚本语言,而PHP8.0版本中引入了一种新的父类调用语法,让面向对象编程更加方便和简洁。在PHP中,我们可以通过继承的方式创建一个父类和一个或多个子类。子类可以继承父类的属性和方法,并可以通过重写父类的方法来修改或扩展其功能。在普通的PHP继承中,如果我们想在子类中调用父类的方法,需要使用parent关键字来引用父

掌握基本的CSS选择器语法,需要具体代码示例CSS选择器是前端开发中非常重要的一部分,它可以用来选择和修改HTML文档的各个元素。掌握基本的CSS选择器语法对于编写高效的样式表是至关重要的。本文将介绍一些常见的CSS选择器以及对应的代码示例。元素选择器元素选择器是最基本的选择器,可以通过元素的标签名来选择对应的元素。例如,要选择所有的段落(p元素),可以使用

C语言中乘方运算的语法和用法简介:在C语言中,乘方运算(poweroperation)是一种常见的数学运算,它用于计算一个数的幂。在C语言中,我们可以使用标准库函数或者自定义函数来实现乘方运算。本文将详细介绍C语言中乘方运算的语法和用法,并提供具体的代码示例。一、使用math.h中的pow()函数在C语言中,math.h标准库中提供了pow()函数,用于执

“match...case”语法类似于其他面向对象语言中的 switch 语句,它旨在使结构与 case 的匹配更容易。让我们开始.语法“match...case”语法如下:def greeting(message): match message.split(): case ["hello"]: print("this message says hello") case ["hello", name]: print("


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

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

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

Dreamweaver CS6
Visual web development tools
