


A preliminary exploration of regular expressions in PHP (1) Basics
Regular expressions are a difficult part for PHP beginners to face. Over time, they tend to forget the functions of various symbols. But after a systematic summary, you will find that the difficulty of memorization is not very difficult.Perl is a common compatible regular expression function, the general form is (preg_), which is what this article mainly introduces.
Learning regular rules is nothing more than learning 1. Writing patterns
2. Regular function = powerful character processing function.
Let’s cover the basics first.
1. Atom, as you can tell from the name, is the smallest unit of a string. It includes two types:
① Printable characters are characters that generally have no special meaning.
②Unprintable characters, representative range:
d: represents any decimal number
D: represents any character other than a number
s: represents any blank character
S: represents any non-whitespace character
w:a-zA-Z0-9
W: Any character except a-zA-Z0-9
(Tips: These are usually the only ones. It’s easy to remember. Just remember that each one has its English abbreviation (d stands for digital, s stands for word, and s stands for space. The meaning is also very clear), and the capital letters are always Will fight with lower case)
2. Customized atom table ([])
[]Character class, matches any one of the atoms, a square bracket matches only one character
The opposite [^] excludes characters and excludes any character in square brackets
[-] represents a certain range, for example: [a-z] represents any character from a to z
Learn more about some common characters.
1. Delimiter (a symbol that makes sure it is a regular string rather than an ordinary string) (| / ...)
Definition: Any symbol other than letters, numbers, and forward slashes is a delimiter symbol. Generally, a backslash (/) is used to represent
Shape like: /tm/
2. Period character (.)
Can match any character except newline character.
A question that can explain this effect well is to write several words starting with s and ending with t.
/^s**t$/ /^s*t/ ……
3. Qualifier (?* {n,m})
? : Matches the previous character 0 or 1 times
: Matches the previous character 1 or more times
* : Matches the previous character 0 or more times
{n}: Match the previous character n times
{n,}: Match the previous character at least n times
{n,m}: Match the previous character at least n times and at most m times
4. Select the character (|)
For example: /cat|dog/ matches cat or dog
5. Bracket characters (())
() has many functions, including new functions produced when used together with functions
1. Increase priority
2. Used as a large atom
3. Used as the sub-mode (1 takes the first sub-mode, 2 takes the second mode...)
"\1" '1'

Golang正则表达式使用管道符|来匹配多个单词或字符串,将各个选项作为逻辑OR表达式分隔开来。例如:匹配"fox"或"dog":fox|dog匹配"quick"、"brown"或"lazy":(quick|brown|lazy)匹配"Go"、"Python"或"Java":Go|Python|Java匹配单词或4位邮政编码:([a-zA

PHP正则表达式是一种针对文本处理和转换的有力工具。它可以通过解析文本内容,并按照特定的模式进行替换或截取,达到有效管理文本信息的目的。其中,正则表达式的一个常见应用是替换以特定字符开头的字符串,对此,我们进行如下的讲解

PHP是一种广泛使用的开源服务器端脚本语言,它可以处理Web开发中所有的任务。PHP在网页开发中的应用广泛,尤其是在动态数据处理上表现优异,因此被众多开发者喜爱和使用。在本篇文章中,我们将一步步地讲解PHP基础知识,帮助初学者从入门到精通。一、基本语法PHP是一种解释性语言,其代码类似于HTML、CSS和JavaScript。每个PHP语句都以分号;结束,注

php用正则去除中文的方法:1、创建一个php示例文件;2、定义一个含有中文和英文的字符串;3、通过“preg_replace('/([\x80-\xff]*)/i','',$a);”正则方法去除查询结果中的中文字符即可。

在本文中,我们将学习如何使用PHP正则表达式删除HTML标签,并从HTML字符串中提取纯文本内容。 为了演示如何去掉HTML标记,让我们首先定义一个包含HTML标签的字符串。

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

使用PHP正则实现中文替换功能的技巧分享在web开发中,经常会遇到需要对中文内容进行替换的情况。PHP作为一种流行的服务器端脚本语言,提供了强大的正则表达式功能,可以很方便地实现中文替换。本文将分享一些在PHP中使用正则实现中文替换的技巧,同时提供具体的代码示例。1.使用preg_replace函数实现中文替换PHP中的preg_replace函数可以用来

Go语言是一种由Google开发的静态类型、编译型语言,其简洁、高效的特性受到了广泛的开发者关注和喜爱。在学习Go语言的过程中,熟练掌握变量的基础知识是至关重要的一步。本文将通过具体的代码示例来讲解Go语言中变量的定义、赋值、类型推断等基础知识,帮助读者更好地理解和掌握这些知识点。在Go语言中,定义一个变量可以使用关键字var,即var变量名变量类型的格


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

Dreamweaver CS6
Visual web development tools

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
