正则表达式学习

本文介绍了正则表达式的概念及用途,并详细列举了常见的元字符及其功能,适合初学者快速入门。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

感想:

正则表达式,xpath,css感觉是一路货。都是用了,看了,就懂;过后不用就忘的那一类。

What Regular Expressions Are Exactly - Terminology

Basically, a regular expression is a pattern describing a certain amount of text. Their name comes from the mathematical theory on which they are based. But we will not dig into that. You will usually find the name abbreviated to "regex" or "regexp".

一、最简单的正则匹配,字符匹配(literal characters)

Twelve characters have special meanings in regular expressions: the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing parenthesis ), the opening square bracket [, and the opening curly brace {. These special characters are often called "metacharacters".

二、元字符

表1.常用的元字符

代码

说明

.( period or dot)

匹配除换行符以外的任意字符

\w

匹配字母或数字或下划线或汉字

\s

匹配任意的空白符

\d

匹配数字

\b

匹配单词的开始或结束

^(caret)

匹配字符串的开始

$(dollar )

匹配字符串的结束

\(backslash)

转义符

|(vertical bar or pipe symbo)

选择符

?( question mark)

零次或一次重复

*(asterisk or star)

零次或多次重复

+(plus sign)

一次或多次重复

( opening parenthesis 

定义分组开始,定义断言开始

)  closing parenthesis

定义分组结束,定义断言结束

[ opening square bracket 

集合定义,如[a-z][aeiou][a|e]

{ opening curly brace

指定重复次数定义,

如:{2}重复2次;

{2,}重复2次或多次

{2,5}重复2次到5次


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值