常用的正则表达式一览

简介: 符号 描述                                          例子(表达式) 例子(匹配的字符串)                  * Matches the preceding character, subexpression, or b...
符号 描述                                          例子(表达式) 例子(匹配的字符串)                
 *

Matches the preceding character, subexpression, or bracketed character,
0 or more times

匹配0次或多次

a*b* aaaaaaaa,
aaabbbbb, bbbbbb        
 +

Matches the preceding character, subexpression, or bracketed character,
1 or more times

匹配1次或多次

a+b+ aaaaaaaab,
aaabbbbb, abbbbbb 
 []

Matches any character within the brackets (i.e., “Pick any one of these
things”)

匹配中括号内的任何字符

[A-Z]* APPLE,
CAPITALS,
QWERTY
 ()

A grouped subexpression (these are evaluated first, in the “order of
operations” of regular expressions)

子表达式

(a*b)* aaabaab, abaaab,
ababaaaaab
 {m, n}

Matches the preceding character, subexpression, or bracketed character
between m and n times (inclusive)

匹配几遍

a{2,3}b{2,3}  aabbb, aaabbb,
aabb 
 [^]

Matches any single character that is not in the brackets

取反 

[^A-Z]*  apple,
lowercase,
qwerty 
 |

Matches any character, string of characters, or subexpression, separated
by the “I” (note that this is a vertical bar, or “pipe,” not a capital “i”)

或者(匹配其中的任何一个) 

b(a|i|e)d  bad, bid, bed 
 .

Matches any single character (including symbols, numbers, a space, etc.)

匹配任意字符(包括字母,数字,空格,其他符号) 

b.d  bad, b9d, bzd, b$d, b d 
 ^

Indicates that a character or subexpression occurs at the beginning of a
string

以XX开头 

^a  apple, a9bp, asdf, a 
 \

An escape character (this allows you to use “special” characters as their
literal meaning)

使用特殊转义符 

\. \| \\  . | \ 
 $

Often used at the end of a regular expression, it means “match this up
to the end of the string.” Without it, every regular expression has a
defacto “.*” at the end of it, accepting strings where only the first part
of the string matches. This can be thougt of as analogous to the ^
symbol.

以XX结尾 

[A-Z]*[a-z]*$  ABCabc, zzzyx, Bob 
 ?!

“Does not contain.” This odd pairing of symbols, immediately preceding
a character (or regular expression), indicates that that character should
not be found in that specific place in the larger string. This can be tricky
to use; after all, the character might be found in a different part of the
string. If trying to eliminate a character entirely, use in conjunction with
a ^ and $ at either end.

不包含 

^((?![A-Z]).)*$  no-caps-here,
$ymb0ls a4e f!ne 
目录
相关文章
|
存储 前端开发 Java
spring boot 实现Minio分片上传
spring boot 实现Minio分片上传
1280 1
|
前端开发 JavaScript 监控
layui框架IE8下的兼容问题收录一
layui框架IE8下的兼容问题收录一
2051 0
|
2月前
|
JSON 安全 API
全网最全面介绍1688API接口指南
1688是阿里巴巴旗下B2B批发平台,其API支持商品搜索、订单管理、数据同步等功能。本文详解API核心概念、权限申请、调用步骤及Python示例,涵盖认证安全、常见问题与最佳实践,助您快速实现系统集成与业务自动化。(239字)
480 1
|
SQL 安全 JavaScript
告别Web安全小白!Python实战指南:抵御SQL注入、XSS、CSRF的秘密武器!
【9月更文挑战第12天】在Web开发中,安全漏洞如同暗礁,尤其对初学者而言,SQL注入、跨站脚本(XSS)和跨站请求伪造(CSRF)是常见挑战。本文通过实战案例,展示如何利用Python应对这些威胁。首先,通过参数化查询防止SQL注入;其次,借助Jinja2模板引擎自动转义机制抵御XSS攻击;最后,使用Flask-WTF库生成和验证CSRF令牌,确保转账功能安全。掌握这些技巧,助你构建更安全的Web应用。
275 5
|
SQL 存储 NoSQL
. NoSQL和SQL的区别、使用场景与选型比较
【7月更文挑战第30天】. NoSQL和SQL的区别、使用场景与选型比较
405 15
|
JavaScript
Vue 打包后打开为空白页面 并且控制台报错‘Failed to load resource: net::ERR_FILE_NOT_FOUND’
Vue 打包后打开为空白页面 并且控制台报错‘Failed to load resource: net::ERR_FILE_NOT_FOUND’
Vue 打包后打开为空白页面 并且控制台报错‘Failed to load resource: net::ERR_FILE_NOT_FOUND’
|
前端开发 JavaScript 搜索推荐
打造个人博客网站:从零开始的HTML、CSS与JavaScript之旅
在这个数字时代,拥有一个个性化的网络空间已成为许多人的梦想。本文将引导你了解如何从零开始,使用HTML、CSS和JavaScript创建属于自己的博客网站。我们将探索这些技术的基础概念,并通过实际代码示例展示如何将静态页面转变为动态交互式网站。无论你是编程新手还是希望扩展技能的开发者,这篇文章都将为你提供一条清晰的学习路径。【8月更文挑战第31天】
|
机器人 API 开发者
Python基于Mirai开发的QQ机器人保姆式教程(亲测可用)
Python基于Mirai开发的QQ机器人保姆式教程(亲测可用)
|
消息中间件 监控 物联网
物联网8大协议介绍及对比
根据具体的应用需求,选择合适的协议可以大幅提升系统的性能和可靠性。希望本文能为您在物联网协议的选择和应用中提供有价值的参考。
3993 0
|
安全 Linux 开发者
Linux笔记之ldd命令详解
`ldd`命令是Linux环境下一个非常实用的工具,用于显示一个程序运行时所需的共享库依赖。它帮助开发者和系统管理员快速诊断程序运行问题,特别是在处理"找不到库文件"或者"错误的库文件版本"等错误时。然而,出于安全的考虑,对于不信任的可执行文件,应该慎用 `ldd`命令,可以考虑使用其他工具如 `objdump`。总的来说,懂得如何妥善且安全地使用 `ldd`,对于维护一个稳定和高效的Linux系统来说,是非常重要的。
786 9