正则表达式备忘录-Regular Expressions Cheatsheet中文版
正则表达式备忘录
Regular Expressions Cheatsheet中文版
原文:https://www.maketecheasier.com/cheatsheet/regex/
|
测试文件a.txt |
|
0x1: If you work with text, you’ll appreciate how useful regular expressions are. 0x00001: Regular expressions are everywhere in Linux for searching through text right down to the character. 0x0000001: This Regular Expressions cheatsheet will be useful for people who simply need a little refresher from time to time. |
|
字符 |
描述 |
例子 |
|
|
. (点) |
任何单个字符,除了换行(\n) |
c.t 匹配 "cat", "cut" 或 "cot."。 '任意字符加im': [root@test: /tmp]# egrep '.im' a.txt who simply need a little refresher from time to time. |
|
|
* (星号) |
重复前一个表达式0或多次 |
12*3 匹配 "13", "123", "1223", "12223"。 与 . 合用代表任何字符。 m.*easier 匹配 "maketecheasier"。 'x加任意个0加1:' [root@test: /tmp]# egrep 'x0*1:' a.txt 0x1: 0x00001: 0x0000001: '任何包含f加任意字符加l' [root@test: /tmp]# egrep 'f.*l' a.txt how useful regular expressions are. will be useful for people |
|
|
+ (加号) |
重复前一个表达式1或多次 |
12+3 匹配 "123","1223","12223" 'x加至少一个0加1:' (比较上一个用*的) [root@test: /tmp]# egrep 'x0+1:' a.txt 0x00001: 0x0000001: |
|
|
? (问号) |
前一个字符可有可无 |
ma?ke 匹配 "make", "mke" '有n或无n加ee' [root@test: /tmp]# egrep 'n?ee' a.txt This Regular Expressions cheatsheet who simply need a little refresher |
|
|
^ (尖号) |
匹配字符串的开头 |
^he 匹配以he开头的 "hello", "hell", "help", "he is a boy" '以空格开头的行' [root@test: /tmp]# egrep '^ ' a.txt how useful regular expressions are. are everywhere in Linux for searching through text right down to the character. will be useful for people who simply need a little refresher from time to time. |
|
|
$ (美刀) |
匹配字符串的结尾 |
ed$ 匹配以ed结尾的 "acted", bed", "greed" '字母e结尾的行' [root@test: /tmp]# egrep 'e$' a.txt you’ll appreciate from time |
|
|
(...) (小括号) |
匹配字符组合 |
(ak) 匹配 "make", "take" '包含 it 的' [root@test: /tmp]# egrep '(it)' a.txt If you work with text, who simply need a little refresher |
|
|
{n} (大括号,n是大于0的整数) |
重复前一个字符n次,n>0 |
12{3}5 匹配 "12225" 'x加4个0加1' [root@test: /tmp]# egrep 'x0{4}1' a.txt 0x00001: |
|
|
[...] (中括号) |
匹配里面的任意一个字符 |
[abc] 匹配字符串"abc"中的"a","b" 或 "c" '所有包含v或b的' [root@test: /tmp]# egrep '[vb]' a.txt are everywhere in Linux will be useful |
|
|
[^...] |
匹配任意字符,除了里面定义的 |
a[^b]c 匹配 "aec", "acc", "adc", 但不匹配 "abc" 'f前面不能是空格或e' [root@test: /tmp]# egrep '[^ e]f' a.txt If you work with text, |
|
|
| (管道符) |
匹配管道符分隔的任一字符串 |
col(o|ou)r 匹配 "color", "colour" |
|
|
- (连字符) |
指定某个范围内的字符一般是[a-z],[A-Z],[1-9],[a-zA-Z1-9] |
a[a-z]c 匹配 "abc", "acc", "adc" |
|
|
\ (反斜线) |
转义符,将特殊符合转义为符号本身 |
a\*c 匹配 "a*c". |
|
|
\n, \r, \t |
代表 换行,回车,制表符 |
||
|
\b...\b |
匹配整个单词 |
\bTech\b 匹配 the word "Tech" in "Make Tech Easier". 找到单词time [root@test: /tmp]# egrep '\btime\b' a.txt from time to time. |
|
正则表达式备忘录-Regular Expressions Cheatsheet中文版的更多相关文章
- 正则表达式(Regular expressions)使用笔记
Regular expressions are a powerful language for matching text patterns. This page gives a basic intr ...
- [笔记] 精通正则表达式/Mastering Regular Expressions
/ 匹配<emphasis>这个tag标注的IP地址的RE:‘<emphasis>([0-9]+(\.[0-9]+){3})</emphasis>' / 锚定--a ...
- Regular Expressions all in one
Regular Expressions all in one Regular Expressions Cheatsheet https://developer.mozilla.org/en-US/do ...
- 自学Zabbix8.1 Regular expressions 正则表达式
点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix8.1 Regular expressions 正则表达式 1. 配置 点击Adm ...
- Python之Regular Expressions(正则表达式)
在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要.正则表达式就是用于描述这些规则的工具.换句话说,正则表达式就是记录文本规则的代码. 很可能你使用过Windows/Dos下用 ...
- 转载:邮箱正则表达式Comparing E-mail Address Validating Regular Expressions
Comparing E-mail Address Validating Regular Expressions Updated: 2/3/2012 Summary This page compares ...
- Regular Expressions --正则表达式官方教程
http://docs.oracle.com/javase/tutorial/essential/regex/index.html This lesson explains how to use th ...
- Regular Expressions in Grep Command with 10 Examples --reference
Regular expressions are used to search and manipulate the text, based on the patterns. Most of the L ...
- Introducing Regular Expressions 学习笔记
Introducing Regular Expressions 读书笔记 工具: regexbuddy:http://download.csdn.net/tag/regexbuddy%E7%A0%B4 ...
随机推荐
- Qt 学习之路 2(50):自定义可编辑模型
Home / Qt 学习之路 2 / Qt 学习之路 2(50):自定义可编辑模型 Qt 学习之路 2(50):自定义可编辑模型 豆子 2013年5月13日 Qt 学习之路 2 13条评论 上一章我们 ...
- 把查询的结果组织为一串字符(eg:板板鞋,兵乓球,篮球,足球)
--把查询的结果组织为一串字符(板板鞋,兵乓球,篮球,足球) drop table a create table a( name varchar(20)) insert into a select ' ...
- redis mac安装配置
去官网下载redis. 解压后 终端cd 至目标文件夹 编译测试: sudo make test 编译安装: sudo make install 输入redis-server启动服务 停止 redis ...
- 网络瓶颈、线程死锁、内存泄露溢出、栈堆、ajax
网络瓶颈:网络传输性能及稳定性的一些相关元素 线程死锁:多个线程因竞争资源造成的一种僵局 下面我们通过一些实例来说明死锁现象. 先看生活中的一个实例,2个人一起吃饭但是只有一双筷子,2人轮流吃(同时拥 ...
- 基于中间件的RBAC权限控制
RBAC 是什么 RBAC(Role-Based Access Control,基于角色的访问控制),就是用户通过角色与权限进行关联. 在 Django 中,权限就是用户对一个包含正则表达式 url ...
- Kibana6.x.x源码分析--启动时无反应分析
今天执行启动命令后,不报错,但是也没有反应,一时不知道是什么原因造成的,后来经过分析发现,无意间删除了根目录下的一个文件夹plugins,重新创建上这个文件夹后,再次运行就OK了.
- HDU_3038 How Many Answers Are Wrong 【带权并查集】
一.题面 HDU3038 二.分析 用并查集可以方便的判断两个位置是否有关系,这种关系可以通过是否有公共父节点判断,如果有公共父节点则可以直接判断是否正确,如果没有公共父节点,就可以把这个条件与之前的 ...
- 1144G Two Merged Sequences ( 贪心+构造)
题目:https://codeforces.com/problemset/problem/1144/G 题意: 将一个序列分成两个序列,两个序列中元素的相对顺序保持和原序列不变,使得分出的两个序列一个 ...
- flex布局在ios8上的兼容性问题
最近在做项目时,使用到了flex布局.其他ios版本都还好,唯独在ios8上遇到了flex布局没起作用的问题.后来经过研究才发现,safari使用的是webkit内核,在ios8上需要单独加一下兼容才 ...
- Python I/O及FIle方法
一.文件操作 文件的编码格式: ASCII与UNICODE: 计算机有256个ASCII字符(8个0/1的排列组合方式一共有256种, 2**8) UTF-8是UNICODE的一种编码格式,计算机中使 ...