From f4c1d1e274cea921e04d87f8488a948d832c4cb9 Mon Sep 17 00:00:00 2001
From: GrayLand
+
+g@e<2DDml7E=_3j
z!Ys6OGrpZDt2P!0OOuJ$Ic?K8OxJ$BpZ<8b`iG-rFIR+oso#RB-ppv46~dHRgnj~n
z#u@b_(663}TXE_C(wn+$sF(d@FhMQs^Og3Rq
MvLiUpp
zH9siDTaDvhW5wG*a6hh~672UVzG&;a3)Ff$fZRk-i(JCsftrh`_(a@I4QE?9$_7P(
z*@WC24b)RUs=99F;6>a1o
+rDdGW%w3xve2Y4`xd6~kFHRqMJ|V4_wP}C7#!1>^5VeRLZdw;Z1TR(xxEYQl
zmnBG&(_e2
#mpquuHF
zv|~`y^rzh&$ih9?es9`>O)#&v<%2!86eJ
+
+
+
+## 什么是正则表达式?
+
+> 正则表达式是一组由字母和符号组成的特殊文本, 它可以用来从文本中找出满足你想要的格式的句子.
+
+
+一个正则表达式是在一个主体字符串中从左到右匹配字符串时的一种样式.
+例如"Regular expression"是一个完整的句子, 但我们常使用缩写的术语"regex"或"regexp".
+正则表达式可以用来替换文本中的字符串,验证形式,提取字符串等等.
+
+想象你正在写一个应用, 然后你想设定一个用户命名的规则, 让用户名包含字符,数字,下划线和连字符,以及限制字符的个数,好让名字看起来没那么丑.
+我们使用以下正则表达式来验证一个用户名:
+
+
+
+
+"the" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/dmRygT/1)
+
+正则表达式`123`匹配字符串`123`. 它逐个字符的与输入的正则表达式做比较.
+
+正则表达式是大小写敏感的, 所以`The`不会匹配`the`.
+
+
+"The" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/1paXsy/1)
+
+## 2. 元字符
+
+正则表达式主要依赖于元字符.
+元字符不代表他们本身的字面意思, 他们都有特殊的含义. 一些元字符写在方括号中的时候有一些特殊的意思. 以下是一些元字符的介绍:
+
+|元字符|描述|
+|:----:|----|
+|.|句号匹配任意单个字符除了换行符.|
+|[ ]|字符种类. 匹配方括号内的任意字符.|
+|[^ ]|否定的字符种类. 匹配除了方括号里的任意字符|
+|*|匹配>=0个重复的在*号之前的字符.|
+|+|匹配>1个重复的+号前的字符.
+|?|标记?之前的字符为可选.|
+|{n,m}|匹配num个中括号之前的字符 (n <= num <= m).|
+|(xyz)|字符集, 匹配与 xyz 完全相等的字符串.|
+|||或运算符,匹配符号前或后的字符.|
+|\|转义字符,用于匹配一些保留的字符 [ ] ( ) { } . * + ? ^ $ \ ||
+|^|从开始行开始匹配.|
+|$|从末端开始匹配.|
+
+## 2.1 点运算符 `.`
+
+`.`是元字符中最简单的例子.
+`.`匹配任意单个字符, 但不匹配换行符.
+例如, 表达式`.ar`匹配一个任意字符后面跟着是`a`和`r`的字符串.
+
+
+".ar" => The car parked in the garage.
+
+
+[在线练习](https://regex101.com/r/xc9GkU/1)
+
+## 2.2 字符集
+
+字符集也叫做字符类.
+方括号用来指定一个字符集.
+在方括号中使用连字符来指定字符集的范围.
+在方括号中的字符集不关心顺序.
+例如, 表达式`[Tt]he` 匹配 `the` 和 `The`.
+
+
+"[Tt]he" => The car parked in the garage.
+
+
+[在线练习](https://regex101.com/r/2ITLQ4/1)
+
+方括号的句号就表示句号.
+表达式 `ar[.]` 匹配 `ar.`字符串
+
+
+"ar[.]" => A garage is a good place to park a car.
+
+
+[在线练习](https://regex101.com/r/wL3xtE/1)
+
+### 2.2.1 否定字符集
+
+一般来说 `^` 表示一个字符串的开头, 但它用在一个方括号的开头的时候, 它表示这个字符集是否定的.
+例如, 表达式`[^c]ar` 匹配一个后面跟着`ar`的除了`c`的任意字符.
+
+
+"[^c]ar" => The car parked in the garage.
+
+
+[在线练习](https://regex101.com/r/nNNlq3/1)
+
+## 2.3 重复次数
+
+后面跟着元字符 `+`, `*` or `?` 的, 用来指定匹配子模式的次数.
+这些元字符在不同的情况下有着不同的意思.
+
+### 2.3.1 `*` 号
+
+`*`号匹配 在`*`之前的字符出现`大于等于0`次.
+例如, 表达式 `a*` 匹配以0或更多个a开头的字符, 因为有0个这个条件, 其实也就匹配了所有的字符. 表达式`[a-z]*` 匹配一个行中所有以小写字母开头的字符串.
+
+
+"[a-z]*" => The car parked in the garage #21.
+
+
+[在线练习](https://regex101.com/r/7m8me5/1)
+
+`*`字符和`.`字符搭配可以匹配所有的字符`.*`.
+`*`和表示匹配空格的符号`\s`连起来用, 如表达式`\s*cat\s*`匹配0或更多个空格开头和0或更多个空格结尾的cat字符串.
+
+
+"\s*cat\s*" => The fat cat sat on the concatenation.
+
+
+[在线练习](https://regex101.com/r/gGrwuz/1)
+
+### 2.3.2 `+` 号
+
+`+`号匹配`+`号之前的字符出现 >=1 次个字符.
+例如表达式`c.+t` 匹配以首字母`c`开头以`t`结尾,中间跟着任意个字符的字符串.
+
+
+"c.+t" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/Dzf9Aa/1)
+
+### 2.3.3 `?` 号
+
+在正则表达式中元字符 `?` 标记在符号前面的字符为可选, 即出现 0 或 1 次.
+例如, 表达式 `[T]?he` 匹配字符串 `he` 和 `The`.
+
+
+"[T]he" => The car is parked in the garage.
+
+
+[在线练习](https://regex101.com/r/cIg9zm/1)
+
+
+"[T]?he" => The car is parked in the garage.
+
+
+[在线练习](https://regex101.com/r/kPpO2x/1)
+
+## 2.4 `{}` 号
+
+在正则表达式中 `{}` 是一个量词, 常用来一个或一组字符可以重复出现的次数.
+例如, 表达式 `[0-9]{2,3}` 匹配 2~3 位 0~9 的数字.
+
+
+
+"[0-9]{2,3}" => The number was 9.9997 but we rounded it off to 10.0.
+
+
+[在线练习](https://regex101.com/r/juM86s/1)
+
+我们可以省略第二个参数.
+例如, `[0-9]{2,}` 匹配至少两位 0~9 的数字.
+
+如果逗号也省略掉则表示重复固定的次数.
+例如, `[0-9]{3}` 匹配3位数字
+
+
+"[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0.
+
+
+[在线练习](https://regex101.com/r/Gdy4w5/1)
+
+
+"[0-9]{3}" => The number was 9.9997 but we rounded it off to 10.0.
+
+
+[在线练习](https://regex101.com/r/Sivu30/1)
+
+## 2.5 `(...)` 特征标群
+
+特征标群是一组写在 `(...)` 中的子模式. 例如之前说的 `{}` 是用来表示前面一个字符出现指定次数. 但如果在 `{}` 前加入特征标群则表示整个标群内的字符重复 N 次. 例如, 表达式 `(ab)*` 匹配连续出现 0 或更多个 `ab`.
+
+我们还可以在 `()` 中用或字符 `|` 表示或. 例如, `(c|g|p)ar` 匹配 `car` 或 `gar` 或 `par`.
+
+
+"(c|g|p)ar" => The car is parked in the garage.
+
+
+[在线练习](https://regex101.com/r/tUxrBG/1)
+
+## 2.6 `|` 或运算符
+
+或运算符就表示或, 用作判断条件.
+
+例如 `(T|t)he|car` 匹配 `(T|t)he` 或 `car`.
+
+
+"(T|t)he|car" => The car is parked in the garage.
+
+
+[在线练习](https://regex101.com/r/fBXyX0/1)
+
+## 2.7 转码特殊字符
+
+反斜线 `\` 在表达式中用于转码紧跟其后的字符. 用于指定 `{ } [ ] / \ + * . $ ^ | ?` 这些特殊字符. 如果想要匹配这些特殊字符则要在其前面加上反斜线 `\`.
+
+例如 `.` 是用来匹配除换行符外的所有字符的. 如果想要匹配句子中的 `.` 则要写成 `\.`.
+
+
+"(f|c|m)at\.?" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/DOc5Nu/1)
+
+## 2.8 锚点
+
+在正则表达式中, 想要匹配指定开头或结尾的字符串就要使用到锚点. `^` 指定开头, `$` 指定结尾.
+
+### 2.8.1 `^` 号
+
+`^` 用来检查匹配的字符串是否在所匹配字符串的开头.
+
+例如, 在 `abc` 中使用表达式 `^a` 会得到结果 `a`. 但如果使用 `^b` 将匹配不到任何结果. 应为在字符串 `abc` 中并不是以 `b` 开头.
+
+例如, `^(T|t)he` 匹配以 `The` 或 `the` 开头的字符串.
+
+
+"(T|t)he" => The car is parked in the garage.
+
+
+[在线练习](https://regex101.com/r/5ljjgB/1)
+
+
+"^(T|t)he" => The car is parked in the garage.
+
+
+[在线练习](https://regex101.com/r/jXrKne/1)
+
+### 2.8.2 `$` 号
+
+同理于 `^` 号, `$` 号用来匹配字符是否是最后一个.
+
+例如, `(at\.)$` 匹配以 `at.` 结尾的字符串.
+
+
+"(at\.)" => The fat cat. sat. on the mat.
+
+
+[在线练习](https://regex101.com/r/y4Au4D/1)
+
+
+"(at\.)$" => The fat cat. sat. on the mat.
+
+
+[在线练习](https://regex101.com/r/t0AkOd/1)
+
+## 3. 简写字符集
+
+正则表达式提供一些常用的字符集简写. 如下:
+
+|简写|描述|
+|:----:|----|
+|.|除换行符外的所有字符|
+|\w|匹配所有字母数字, 等同于 `[a-zA-Z0-9_]`|
+|\W|匹配所有非字母数字, 即符号, 等同于: `[^\w]`|
+|\d|匹配数字: `[0-9]`|
+|\D|匹配非数字: `[^\d]`|
+|\s|匹配所有空格字符, 等同于: `[\t\n\f\r\p{Z}]`|
+|\S|匹配所有非空格字符: `[^\s]`|
+
+## 4. 前后关联约束(前后预查)
+
+前置约束和后置约束都属于**非捕获簇**(用于匹配不在匹配列表中的格式).
+前置约束用于判断所匹配的格式是否在另一个确定的格式之后.
+
+例如, 我们想要获得所有跟在 `$` 符号后的数字, 我们可以使用正向向后约束 `(?<=\$)[0-9\.]*`.
+这个表达式匹配 `$` 开头, 之后跟着 `0,1,2,3,4,5,6,7,8,9,.` 这些字符可以出现大于等于 0 次.
+
+前后关联约束如下:
+
+|符号|描述|
+|:----:|----|
+|?=|前置约束-存在|
+|?!|前置约束-排除|
+|?<=|后置约束-存在|
+|?
+"[T|t]he(?=\sfat)" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/IDDARt/1)
+
+### 4.2 `?!...` 前置约束-排除
+
+前置约束-排除 `?!` 用于筛选所有匹配结果, 筛选条件为 其后不跟随着定义的格式
+`前置约束-排除` 定义和 `前置约束(存在)` 一样, 区别就是 `=` 替换成 `!` 也就是 `(?!...)`.
+
+表达式 `[T|t]he(?!\sfat)` 匹配 `The` 和 `the`, 且其后不跟着 `(空格)fat`.
+
+
+"[T|t]he(?!\sfat)" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/V32Npg/1)
+
+### 4.3 `?<= ...` 后置约束-存在
+
+后置约束-存在 记作`(?<=...)` 用于筛选所有匹配结果, 筛选条件为 其前跟随着定义的格式.
+例如, 表达式 `(?<=[T|t]he\s)(fat|mat)` 匹配 `fat` 和 `mat`, 且其前跟着 `The` 或 `the`.
+
+
+"(?<=[T|t]he\s)(fat|mat)" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/avH165/1)
+
+### 4.4 `?
+"(?<![T|t]he\s)(cat)" => The cat sat on cat.
+
+
+[在线练习](https://regex101.com/r/8Efx5G/1)
+
+## 5. 标志
+
+标志也叫修饰语, 因为它可以用来修改表达式的搜索结果.
+这些标志可以任意的组合使用, 它也是整个正则表达式的一部分.
+
+|标志|描述|
+|:----:|----|
+|i|忽略大小写.|
+|g|全局搜索.|
+|m|多行的: 锚点元字符 `^` `$` 工作范围在每行的起始.|
+
+### 5.1 忽略大小写 (Case Insensitive)
+
+修饰语 `i` 用于忽略大小写.
+例如, 表达式 `/The/gi` 表示在全局搜索 `The`, 在后面的 `i` 将其条件修改为忽略大小写, 则变成搜索 `the` 和 `The`, `g` 表示全局搜索.
+
+
+"The" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/dpQyf9/1)
+
+
+"/The/gi" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/ahfiuh/1)
+
+### 5.2 全局搜索 (Global search)
+
+修饰符 `g` 常用语执行一个全局搜索匹配, 即(不仅仅返回第一个匹配的, 而是返回全部).
+例如, 表达式 `/.(at)/g` 表示搜索 任意字符(除了换行) + `at`, 并返回全部结果.
+
+
+"/.(at)/" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/jnk6gM/1)
+
+
+"/.(at)/g" => The fat cat sat on the mat.
+
+
+[在线练习](https://regex101.com/r/dO1nef/1)
+
+### 5.3 多行修饰符 (Multiline)
+
+多行修饰符 `m` 常用语执行一个多行匹配.
+
+像之前介绍的 `(^,$)` 用于检查格式是否是在待检测字符串的开头或结尾. 但我们如果想要它在每行的开头和结尾生效, 我们需要用到多行修饰符 `m`.
+
+例如, 表达式 `/at(.)?$/gm` 表示在待检测字符串每行的末尾搜索 `at`后跟一个或多个 `.` 的字符串, 并返回全部结果.
+
+
+"/.at(.)?$/" => The fat
+ cat sat
+ on the mat.
+
+
+[在线练习](https://regex101.com/r/hoGMkP/1)
+
+
+"/.at(.)?$/gm" => The fat
+ cat sat
+ on the mat.
+
+
+[在线练习](https://regex101.com/r/E88WE2/1)
+
+## 额外补充
+
+* *正整数*: `^\d+$`
+* *负整数*: `^-\d+$`
+* *手机国家号*: `^+?[\d\s]{3,}$`
+* *手机号*: `^+?[\d\s]+(?[\d\s]{10,}$`
+* *整数*: `^-?\d+$`
+* *用户名*: `^[\w\d_.]{4,16}$`
+* *数字和英文字母*: `^[a-zA-Z0-9]*$`
+* *数字和应为字母和空格*: `^[a-zA-Z0-9 ]*$`
+* *密码*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$`
+* *邮箱*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$`
+* *IP4 地址*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$`
+* *纯小写字母*: `^([a-z])*$`
+* *纯大写字母*: `^([A-Z])*$`
+* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$`
+* *VISA 信用卡号*: `^(4[0-9]{12}(?:[0-9]{3})?)*$`
+* *日期 (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$`
+* *日期 (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$`
+* *MasterCard 信用卡号*: `^(5[1-5][0-9]{14})*$`
+
+## 贡献
+
+* 报告问题
+* 开放合并请求
+* 传播此文档
+* 直接和我联系 ziishaned@gmail.com 或 [](https://twitter.com/ziishaned)
+
+## 许可证
+
+MIT © [Zeeshan Ahmed](mailto:ziishaned@gmail.com)
diff --git a/README.md b/README.md
index 1a9ba3db..84cfc679 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,9 @@
MvLiUpp zH9siDTaDvhW5wG*a6hh~672UVzG&;a3)Ff$fZRk-i(JCsftrh`_(a@I4QE?9$_7P( z*@WC24b)RUs=99F;6>a1oVI64%D>{LYj#q=)~ISUj=>4zSfKkqc-{x$?E30r`2 zx^ZYh!Z=CDzMA*5G}qFs`9`?|iiqAtZ-8Kpi4m3@YFJ4_2tsL(u%UhMXHeoEVf_Sb z0~A`ow!SsLuPALz;J(K`ZWXzf%saAE! @qZwoBUd?NAj#f1ur=(Vd*NIl{*OhkUm8Q6sZ%opPoc%bbn1iD&U3!Y1 zyYN~4>5;>0QDep^gi}8QN&E4Pr0hDP*P7KORKpAweBQiI&bf}TKMfig<>u#lK3=zO z^PslwEnGX(?R1APlX%rn*-A;6(Wd}1f5<7q^DHLaEg{Rw(Yw2ewnjx-#veD%Ym3lf zg=bk3XRWUgUW?SfLpPrb+<6+rjNL MXz5+cgUNCr(1v~ADaDw@H)e 1G>(}eo8^z3rjv0B?nch1h<#n mE<;HyNkJ1VqHmH@NVdIh z`5;o*kekD*2U 5 zRj?i9X}hv@0in#V0>C33sI2_>8A(5ZFc=)i)%0|z`}_QCV3S;67OxxIXugJ(Lq?KA zbpK*?&P$8hZYQIGg)L^wc2IfUoOaIO)RR)h)-7(LQ}NceJ_K6hIL`YmOef|FE0V^) zezwvaF4?X~3mB}sWHi!ajL^eSoxz=~$umLqvW6d@)s05o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NbWwfyH09`Duozf7LJK 3T53|l z1mdDewsRJ!f+vgW2g$B-LPAeO5bGS^pn-kG#Afx?m-E22z@kut=Vv)#)O4dJrdu(0 zEuJuez$&Y$+A$gDJ{B9!(@4S0;)e4Jrz6l0SVQz)F-hP?msE2EEWbW= lJn1&OUzL!R{FUla*SA2SxXnSKvZ6GAB!OYCGa x78>Un*0H^$2hGGJ}eIJB8;dt7q zVF`1!!)8Us>O_r{wje`b=eWkaZToQi!1Zxkes}oed@5n`k;7;u>yiB4ed+}enH=Ir zQG!Qhm%1DRpHCWUFNl^aS})R+{}Lb)qdB5GON*yK6*N9^4Ilb;*!KVLAoPD8f7NsU gpU~k&M$5rzmc?MbpjDrv-?>v$(!Nu6``+XK1==UaD*ylh literal 0 HcmV?d00001 diff --git a/README-zh-simple.md b/README-zh-simple.md new file mode 100644 index 00000000..2ae80013 --- /dev/null +++ b/README-zh-simple.md @@ -0,0 +1,488 @@ +
++
+
+ +## 什么是正则表达式? + +> 正则表达式是一组由字母和符号组成的特殊文本, 它可以用来从文本中找出满足你想要的格式的句子. + + +一个正则表达式是在一个主体字符串中从左到右匹配字符串时的一种样式. +例如"Regular expression"是一个完整的句子, 但我们常使用缩写的术语"regex"或"regexp". +正则表达式可以用来替换文本中的字符串,验证形式,提取字符串等等. + +想象你正在写一个应用, 然后你想设定一个用户命名的规则, 让用户名包含字符,数字,下划线和连字符,以及限制字符的个数,好让名字看起来没那么丑. +我们使用以下正则表达式来验证一个用户名: + +
++
+ +以上的正则表达式可以接受 `john_doe`, `jo-hn_doe`, `john12_as`. +但不匹配`Jo`, 因为它包含了大写的字母而且太短了. + +目录 +================= + + * [1. 基本匹配](#1-基本匹配) + * [2. 元字符](#2-元字符) + * [2.1 点运算符 .](#21-点运算符-) + * [2.2 字符集](#22-字符集) + * [2.2.1 否定字符集](#221-否定字符集) + * [2.3 重复次数](#23-重复次数) + * [2.3.1 * 号](#231--号) + * [2.3.2 号](#232--号) + * [2.3.3 ? 号](#233--号) + * [2.4 {} 号](#24--号) + * [2.5 (...) 特征标群](#25--特征标群) + * [2.6 | 或运算符](#26--或运算符) + * [2.7 转码特殊字符](#27-转码特殊字符) + * [2.8 锚点](#28-锚点) + * [2.8.1 ^ 号](#281--号) + * [2.8.2 $ 号](#282--号) +* [3. 简写字符集](#3-简写字符集) +* [4. 前后关联约束(前后预查)](#4-前后关联约束前后预查) + * [4.1 ?=... 前置约束(存在)](#41--前置约束存在) + * [4.2 ?!... 前置约束-排除](#42--前置约束-排除) + * [4.3 ?<= ... 后置约束-存在](#43---后置约束-存在) + * [4.4 ?<!... 后置约束-排除](#44--后置约束-排除) +* [5. 标志](#5-标志) + * [5.1 忽略大小写 (Case Insensitive)](#51-忽略大小写-case-insensitive) + * [5.2 全局搜索 (Global search)](#52-全局搜索-global-search) + * [5.3 多行修饰符 (Multiline)](#53-多行修饰符-multiline) +* [额外补充](#额外补充) +* [贡献](#贡献) +* [许可证](#许可证) + +## 1. 基本匹配 + +正则表达式其实就是在执行搜索时的格式, 它由一些字母和数字组合而成. +例如: 一个正则表达式 `the`, 它表示一个规则: 由字母`t`开始,接着是`h`,再接着是`e`. + ++
+"the" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/dmRygT/1) + +正则表达式`123`匹配字符串`123`. 它逐个字符的与输入的正则表达式做比较. + +正则表达式是大小写敏感的, 所以`The`不会匹配`the`. + ++"The" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/1paXsy/1) + +## 2. 元字符 + +正则表达式主要依赖于元字符. +元字符不代表他们本身的字面意思, 他们都有特殊的含义. 一些元字符写在方括号中的时候有一些特殊的意思. 以下是一些元字符的介绍: + +|元字符|描述| +|:----:|----| +|.|句号匹配任意单个字符除了换行符.| +|[ ]|字符种类. 匹配方括号内的任意字符.| +|[^ ]|否定的字符种类. 匹配除了方括号里的任意字符| +|*|匹配>=0个重复的在*号之前的字符.| +|+|匹配>1个重复的+号前的字符. +|?|标记?之前的字符为可选.| +|{n,m}|匹配num个中括号之前的字符 (n <= num <= m).| +|(xyz)|字符集, 匹配与 xyz 完全相等的字符串.| +|||或运算符,匹配符号前或后的字符.| +|\|转义字符,用于匹配一些保留的字符[ ] ( ) { } . * + ? ^ $ \ || +|^|从开始行开始匹配.| +|$|从末端开始匹配.| + +## 2.1 点运算符 `.` + +`.`是元字符中最简单的例子. +`.`匹配任意单个字符, 但不匹配换行符. +例如, 表达式`.ar`匹配一个任意字符后面跟着是`a`和`r`的字符串. + ++".ar" => The car parked in the garage. ++ +[在线练习](https://regex101.com/r/xc9GkU/1) + +## 2.2 字符集 + +字符集也叫做字符类. +方括号用来指定一个字符集. +在方括号中使用连字符来指定字符集的范围. +在方括号中的字符集不关心顺序. +例如, 表达式`[Tt]he` 匹配 `the` 和 `The`. + ++"[Tt]he" => The car parked in the garage. ++ +[在线练习](https://regex101.com/r/2ITLQ4/1) + +方括号的句号就表示句号. +表达式 `ar[.]` 匹配 `ar.`字符串 + ++"ar[.]" => A garage is a good place to park a car. ++ +[在线练习](https://regex101.com/r/wL3xtE/1) + +### 2.2.1 否定字符集 + +一般来说 `^` 表示一个字符串的开头, 但它用在一个方括号的开头的时候, 它表示这个字符集是否定的. +例如, 表达式`[^c]ar` 匹配一个后面跟着`ar`的除了`c`的任意字符. + ++"[^c]ar" => The car parked in the garage. ++ +[在线练习](https://regex101.com/r/nNNlq3/1) + +## 2.3 重复次数 + +后面跟着元字符 `+`, `*` or `?` 的, 用来指定匹配子模式的次数. +这些元字符在不同的情况下有着不同的意思. + +### 2.3.1 `*` 号 + +`*`号匹配 在`*`之前的字符出现`大于等于0`次. +例如, 表达式 `a*` 匹配以0或更多个a开头的字符, 因为有0个这个条件, 其实也就匹配了所有的字符. 表达式`[a-z]*` 匹配一个行中所有以小写字母开头的字符串. + ++"[a-z]*" => The car parked in the garage #21. ++ +[在线练习](https://regex101.com/r/7m8me5/1) + +`*`字符和`.`字符搭配可以匹配所有的字符`.*`. +`*`和表示匹配空格的符号`\s`连起来用, 如表达式`\s*cat\s*`匹配0或更多个空格开头和0或更多个空格结尾的cat字符串. + ++"\s*cat\s*" => The fat cat sat on the concatenation. ++ +[在线练习](https://regex101.com/r/gGrwuz/1) + +### 2.3.2 `+` 号 + +`+`号匹配`+`号之前的字符出现 >=1 次个字符. +例如表达式`c.+t` 匹配以首字母`c`开头以`t`结尾,中间跟着任意个字符的字符串. + ++"c.+t" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/Dzf9Aa/1) + +### 2.3.3 `?` 号 + +在正则表达式中元字符 `?` 标记在符号前面的字符为可选, 即出现 0 或 1 次. +例如, 表达式 `[T]?he` 匹配字符串 `he` 和 `The`. + ++"[T]he" => The car is parked in the garage. ++ +[在线练习](https://regex101.com/r/cIg9zm/1) + ++"[T]?he" => The car is parked in the garage. ++ +[在线练习](https://regex101.com/r/kPpO2x/1) + +## 2.4 `{}` 号 + +在正则表达式中 `{}` 是一个量词, 常用来一个或一组字符可以重复出现的次数. +例如, 表达式 `[0-9]{2,3}` 匹配 2~3 位 0~9 的数字. + + ++"[0-9]{2,3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[在线练习](https://regex101.com/r/juM86s/1) + +我们可以省略第二个参数. +例如, `[0-9]{2,}` 匹配至少两位 0~9 的数字. + +如果逗号也省略掉则表示重复固定的次数. +例如, `[0-9]{3}` 匹配3位数字 + ++"[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[在线练习](https://regex101.com/r/Gdy4w5/1) + ++"[0-9]{3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[在线练习](https://regex101.com/r/Sivu30/1) + +## 2.5 `(...)` 特征标群 + +特征标群是一组写在 `(...)` 中的子模式. 例如之前说的 `{}` 是用来表示前面一个字符出现指定次数. 但如果在 `{}` 前加入特征标群则表示整个标群内的字符重复 N 次. 例如, 表达式 `(ab)*` 匹配连续出现 0 或更多个 `ab`. + +我们还可以在 `()` 中用或字符 `|` 表示或. 例如, `(c|g|p)ar` 匹配 `car` 或 `gar` 或 `par`. + ++"(c|g|p)ar" => The car is parked in the garage. ++ +[在线练习](https://regex101.com/r/tUxrBG/1) + +## 2.6 `|` 或运算符 + +或运算符就表示或, 用作判断条件. + +例如 `(T|t)he|car` 匹配 `(T|t)he` 或 `car`. + ++"(T|t)he|car" => The car is parked in the garage. ++ +[在线练习](https://regex101.com/r/fBXyX0/1) + +## 2.7 转码特殊字符 + +反斜线 `\` 在表达式中用于转码紧跟其后的字符. 用于指定 `{ } [ ] / \ + * . $ ^ | ?` 这些特殊字符. 如果想要匹配这些特殊字符则要在其前面加上反斜线 `\`. + +例如 `.` 是用来匹配除换行符外的所有字符的. 如果想要匹配句子中的 `.` 则要写成 `\.`. + ++"(f|c|m)at\.?" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/DOc5Nu/1) + +## 2.8 锚点 + +在正则表达式中, 想要匹配指定开头或结尾的字符串就要使用到锚点. `^` 指定开头, `$` 指定结尾. + +### 2.8.1 `^` 号 + +`^` 用来检查匹配的字符串是否在所匹配字符串的开头. + +例如, 在 `abc` 中使用表达式 `^a` 会得到结果 `a`. 但如果使用 `^b` 将匹配不到任何结果. 应为在字符串 `abc` 中并不是以 `b` 开头. + +例如, `^(T|t)he` 匹配以 `The` 或 `the` 开头的字符串. + ++"(T|t)he" => The car is parked in the garage. ++ +[在线练习](https://regex101.com/r/5ljjgB/1) + ++"^(T|t)he" => The car is parked in the garage. ++ +[在线练习](https://regex101.com/r/jXrKne/1) + +### 2.8.2 `$` 号 + +同理于 `^` 号, `$` 号用来匹配字符是否是最后一个. + +例如, `(at\.)$` 匹配以 `at.` 结尾的字符串. + ++"(at\.)" => The fat cat. sat. on the mat. ++ +[在线练习](https://regex101.com/r/y4Au4D/1) + ++"(at\.)$" => The fat cat. sat. on the mat. ++ +[在线练习](https://regex101.com/r/t0AkOd/1) + +## 3. 简写字符集 + +正则表达式提供一些常用的字符集简写. 如下: + +|简写|描述| +|:----:|----| +|.|除换行符外的所有字符| +|\w|匹配所有字母数字, 等同于 `[a-zA-Z0-9_]`| +|\W|匹配所有非字母数字, 即符号, 等同于: `[^\w]`| +|\d|匹配数字: `[0-9]`| +|\D|匹配非数字: `[^\d]`| +|\s|匹配所有空格字符, 等同于: `[\t\n\f\r\p{Z}]`| +|\S|匹配所有非空格字符: `[^\s]`| + +## 4. 前后关联约束(前后预查) + +前置约束和后置约束都属于**非捕获簇**(用于匹配不在匹配列表中的格式). +前置约束用于判断所匹配的格式是否在另一个确定的格式之后. + +例如, 我们想要获得所有跟在 `$` 符号后的数字, 我们可以使用正向向后约束 `(?<=\$)[0-9\.]*`. +这个表达式匹配 `$` 开头, 之后跟着 `0,1,2,3,4,5,6,7,8,9,.` 这些字符可以出现大于等于 0 次. + +前后关联约束如下: + +|符号|描述| +|:----:|----| +|?=|前置约束-存在| +|?!|前置约束-排除| +|?<=|后置约束-存在| +|? +"[T|t]he(?=\sfat)" => The fat cat sat on the mat. + + +[在线练习](https://regex101.com/r/IDDARt/1) + +### 4.2 `?!...` 前置约束-排除 + +前置约束-排除 `?!` 用于筛选所有匹配结果, 筛选条件为 其后不跟随着定义的格式 +`前置约束-排除` 定义和 `前置约束(存在)` 一样, 区别就是 `=` 替换成 `!` 也就是 `(?!...)`. + +表达式 `[T|t]he(?!\sfat)` 匹配 `The` 和 `the`, 且其后不跟着 `(空格)fat`. + ++"[T|t]he(?!\sfat)" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/V32Npg/1) + +### 4.3 `?<= ...` 后置约束-存在 + +后置约束-存在 记作`(?<=...)` 用于筛选所有匹配结果, 筛选条件为 其前跟随着定义的格式. +例如, 表达式 `(?<=[T|t]he\s)(fat|mat)` 匹配 `fat` 和 `mat`, 且其前跟着 `The` 或 `the`. + ++"(?<=[T|t]he\s)(fat|mat)" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/avH165/1) + +### 4.4 `? +"(?<![T|t]he\s)(cat)" => The cat sat on cat. + + +[在线练习](https://regex101.com/r/8Efx5G/1) + +## 5. 标志 + +标志也叫修饰语, 因为它可以用来修改表达式的搜索结果. +这些标志可以任意的组合使用, 它也是整个正则表达式的一部分. + +|标志|描述| +|:----:|----| +|i|忽略大小写.| +|g|全局搜索.| +|m|多行的: 锚点元字符 `^` `$` 工作范围在每行的起始.| + +### 5.1 忽略大小写 (Case Insensitive) + +修饰语 `i` 用于忽略大小写. +例如, 表达式 `/The/gi` 表示在全局搜索 `The`, 在后面的 `i` 将其条件修改为忽略大小写, 则变成搜索 `the` 和 `The`, `g` 表示全局搜索. + ++"The" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/dpQyf9/1) + ++"/The/gi" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/ahfiuh/1) + +### 5.2 全局搜索 (Global search) + +修饰符 `g` 常用语执行一个全局搜索匹配, 即(不仅仅返回第一个匹配的, 而是返回全部). +例如, 表达式 `/.(at)/g` 表示搜索 任意字符(除了换行) + `at`, 并返回全部结果. + ++"/.(at)/" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/jnk6gM/1) + ++"/.(at)/g" => The fat cat sat on the mat. ++ +[在线练习](https://regex101.com/r/dO1nef/1) + +### 5.3 多行修饰符 (Multiline) + +多行修饰符 `m` 常用语执行一个多行匹配. + +像之前介绍的 `(^,$)` 用于检查格式是否是在待检测字符串的开头或结尾. 但我们如果想要它在每行的开头和结尾生效, 我们需要用到多行修饰符 `m`. + +例如, 表达式 `/at(.)?$/gm` 表示在待检测字符串每行的末尾搜索 `at`后跟一个或多个 `.` 的字符串, 并返回全部结果. + ++"/.at(.)?$/" => The fat + cat sat + on the mat. ++ +[在线练习](https://regex101.com/r/hoGMkP/1) + ++"/.at(.)?$/gm" => The fat + cat sat + on the mat. ++ +[在线练习](https://regex101.com/r/E88WE2/1) + +## 额外补充 + +* *正整数*: `^\d+$` +* *负整数*: `^-\d+$` +* *手机国家号*: `^+?[\d\s]{3,}$` +* *手机号*: `^+?[\d\s]+(?[\d\s]{10,}$` +* *整数*: `^-?\d+$` +* *用户名*: `^[\w\d_.]{4,16}$` +* *数字和英文字母*: `^[a-zA-Z0-9]*$` +* *数字和应为字母和空格*: `^[a-zA-Z0-9 ]*$` +* *密码*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` +* *邮箱*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$` +* *IP4 地址*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` +* *纯小写字母*: `^([a-z])*$` +* *纯大写字母*: `^([A-Z])*$` +* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` +* *VISA 信用卡号*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` +* *日期 (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` +* *日期 (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` +* *MasterCard 信用卡号*: `^(5[1-5][0-9]{14})*$` + +## 贡献 + +* 报告问题 +* 开放合并请求 +* 传播此文档 +* 直接和我联系 ziishaned@gmail.com 或 [](https://twitter.com/ziishaned) + +## 许可证 + +MIT © [Zeeshan Ahmed](mailto:ziishaned@gmail.com) diff --git a/README.md b/README.md index e1f83e48..cb68020e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@![]()
+ +[中文版](README-zh-simple.md) + ## What is Regular Expression? > Regular expression is a group of characters or symbols which is used to find a specific pattern from a text. From 41a1cfc06f8da72d5849ed76229f613eecbbfa79 Mon Sep 17 00:00:00 2001 From: Zeeshan AhmedDate: Fri, 11 Aug 2017 14:40:19 +0100 Subject: [PATCH 003/212] Update image link --- 01.png | Bin 20284 -> 0 bytes README-zh-simple.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 01.png diff --git a/01.png b/01.png deleted file mode 100644 index 0d1c9340772a1ab2237859ed4f2e45cfc6fa50cd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20284 zcmeIaXH-*BxG1QI3W|zSL=li?=twW2DblO-j!N&+JBSJ>2uSE91SO$J69^zkvrs}O zlt_(836UltfT6wvw)^J&nwdLm&AsdT$HPAR?EUq&zn$m0+A8PHTs?E_*s*hJs(18` z9U}`ocI y7PwjK}c1OnV1 z0<(@ClL?Rp9^LGG?q3gZb9MKY4v=L#njsB59}Ww$T|b)Q<08vuqNRIX(ZkE`x|o2d zz)d!}GuN+Qm+`W-m)5(Z{QGm@FIhH6AD@TPf`b13{sR6Y0v=utf >9J!9$JFlJG6*=n45i#f*i0T=vEjDk(vV57n6D7!;oe w{n&8|g=1vYkN)dDMkTbABWE=< zQX4A?eUK>wy&QXwqR)|Nq^LL5TH}y?Bz*Ett2O$L2595??LR0+G;#iD&Lm9;EiAaU z#&Yi^`)H)HBw6dtUU5?HcBEdR|IVB`M0)qlU!vbm%~Az>Bd}o{A;vM@#fcL`Z&_aa zO|qfqk94?iQXtj820Bygl&9*3c;Y?rYTRQVWB52_`DL#O!&p8tl;n4i<1YxYQ>NVw zVR6b4)z9Q;w5~Vd0h9Cx$n4v@wQVy3-HV__Pno_XsHJIuRWGQ?r^a+I23p=d9{86f zxme2XezGOaMnUsuP*I#UY_5GaoY$* )$_55=_&x)Ts z#A0Posz4&O&3UJI+8Vx*>GQU}Q}zZZP)p%1)o+d~99&F)#XUX{Xf3{BubtBzi}S17 z4SnZ}0Ku_pVQ|J}G9`=f_4HRa?%WM!`iQsSB|@q90Mk$DZ>X0oTt+CR4V2&R-e2 zO1q8hl~4bo6BLbnKC6-||8i*}RB7xs;lj-lCC+gwr{aMxyGf19bXfKU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l^aS})R+{}Lb)qdB5GON*yK6*N9^4Ilb;*!KVLAoPD8f7NsU gpU~k&M$5rzmc?MbpjDrv-?>v$(!Nu6``+XK1==UaD*ylh diff --git a/README-zh-simple.md b/README-zh-simple.md index 2ae80013..6caf5128 100644 --- a/README-zh-simple.md +++ b/README-zh-simple.md @@ -17,7 +17,7 @@
-
以上的正则表达式可以接受 `john_doe`, `jo-hn_doe`, `john12_as`. From 1bca89cd8894369634c32bddc5163e862ab9af28 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed+
![]()
Date: Fri, 11 Aug 2017 14:42:25 +0100 Subject: [PATCH 004/212] Rename readme --- README-zh-simple.md => README-cn.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README-zh-simple.md => README-cn.md (100%) diff --git a/README-zh-simple.md b/README-cn.md similarity index 100% rename from README-zh-simple.md rename to README-cn.md From e390ba3fb29325b213411658454a612fc93f540f Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Fri, 11 Aug 2017 18:53:12 +0500 Subject: [PATCH 005/212] Add translations section in readme --- README-cn.md | 5 +++++ README.md | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README-cn.md b/README-cn.md index 6caf5128..571aaaa1 100644 --- a/README-cn.md +++ b/README-cn.md @@ -3,6 +3,11 @@ ![]()
+## 翻译: + +* [English](README.md) +* [中文版](README-cn.md) + ## 什么是正则表达式? > 正则表达式是一组由字母和符号组成的特殊文本, 它可以用来从文本中找出满足你想要的格式的句子. diff --git a/README.md b/README.md index cb68020e..9137d8a5 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,10 @@![]()
+## Translations: -[中文版](README-zh-simple.md) +* [English](README.md) +* [中文版](README-cn.md) ## What is Regular Expression? From c1cfb1e6fe30d455b5b28bddc95562c9e60cf471 Mon Sep 17 00:00:00 2001 From: Loisaida SamDate: Fri, 11 Aug 2017 10:01:09 -0400 Subject: [PATCH 006/212] Username update (#39) As pointed out by @jdp - `\d` and `_` are a subset of `\w`. Maybe worth mentioning that most places don't allow usernames to start with a number, underscore, or dot. Even more generally speaking, these are nice toy/model illustrations, but maybe it's worth pointing out that while fun for practice, maybe regex isn't the best way to validate some of these things. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9137d8a5..43b80d31 100644 --- a/README.md +++ b/README.md @@ -474,7 +474,7 @@ line. And because of `m` flag now regular expression engine matches pattern at t * *US Phone Number*: `^+?[\d\s]{3,}$` * *US Phone with code*: `^+?[\d\s]+(?[\d\s]{10,}$` * *Integers*: `^-?\d+$` -* *Username*: `^[\w\d_.]{4,16}$` +* *Username*: `^[\w.]{4,16}$` * *Alpha-numeric characters*: `^[a-zA-Z0-9]*$` * *Alpha-numeric characters with spaces*: `^[a-zA-Z0-9 ]*$` * *Password*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` From d60813e00fdde0f00e33cfb80884308385818a1d Mon Sep 17 00:00:00 2001 From: Tibor Martini Date: Sat, 12 Aug 2017 02:41:43 +0200 Subject: [PATCH 007/212] Update README.md (#31) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43b80d31..c4e8f024 100644 --- a/README.md +++ b/README.md @@ -173,8 +173,8 @@ zero or more spaces. ### 2.3.2 The Plus -The symbol `+` matches one or more repetitions of the preceding character. For example, the regular expression `c.+t` means: lowercase -letter `c`, followed by any number of character, followed by the lowercase character `t`. +The symbol `+` matches one or more repetitions of the preceding character. For example, the regular expression `c.+t` means: lowercase +letter `c`, followed by at least one character, followed by the lowercase character `t`. "c.+t" => The fat cat sat on the mat. From 23a0431e853d46bb0646dfbb160a447999686d43 Mon Sep 17 00:00:00 2001 From: Tibor Martini+ +[正規表現の動作確認をする](https://regex101.com/r/8Efx5G/1) + +## 5. フラグ + +フラグは修飾子とも呼ばれ、正規表現の結果を修正するために使用されます。 +フラグは任意の順序・組み合わせで使用でき、正規表現では必要不可欠な機能です。 + +|フラグ|説明 | +|:----:|------------------------------------------------------------------------| +|i |大文字・小文字を区別しない: マッチングで大文字・小文字が区別されなくなる| +|g |グローバル検索: 入力文字列の全マッチ列を検索する | +|m |複数行: 複数行をマッチさせるためのアンカー | + +### 5.1 大文字・小文字を区別しない + +修飾子 `i` は大文字・小文字を区別しなくないときに使用します。 +例えば `/The/gi` という正規表現は大文字の `T` の後に小文字の `h`, `e` が続くという意味ですが、 +最後の `i` で大文字・小文字を区別しない設定にしています。 +文字列内の全マッチ列を検索したいのでフラグ `g` も渡しています。 + +Date: Sat, 12 Aug 2017 02:46:13 +0200 Subject: [PATCH 008/212] Update email regex to match gTLDs (#32) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c4e8f024..c73218c1 100644 --- a/README.md +++ b/README.md @@ -478,7 +478,7 @@ line. And because of `m` flag now regular expression engine matches pattern at t * *Alpha-numeric characters*: `^[a-zA-Z0-9]*$` * *Alpha-numeric characters with spaces*: `^[a-zA-Z0-9 ]*$` * *Password*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` -* *email*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$` +* *email*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})*$` * *IPv4 address*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` * *Lowercase letters only*: `^([a-z])*$` * *Uppercase letters only*: `^([A-Z])*$` From fc81f7b39da2025c8c1527efa3630124f5c6aab7 Mon Sep 17 00:00:00 2001 From: Daniele Foroni Date: Sat, 12 Aug 2017 02:47:07 +0200 Subject: [PATCH 009/212] Added regex for Italian date format (#35) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c73218c1..8d32affe 100644 --- a/README.md +++ b/README.md @@ -484,6 +484,7 @@ line. And because of `m` flag now regular expression engine matches pattern at t * *Uppercase letters only*: `^([A-Z])*$` * *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` * *VISA credit card numbers*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` +* *Date (DD/MM/YYYY)*: `^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$` * *Date (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` * *Date (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` * *MasterCard credit card numbers*: `^(5[1-5][0-9]{14})*$` From e8532bf629526c91947ff6b1b946fbe667e59710 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Sat, 12 Aug 2017 06:42:44 +0500 Subject: [PATCH 010/212] Fixes #29 grammatical mistakes --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8d32affe..1df58ace 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ A regular expression is a pattern that is matched against a subject string from mouthful, you will usually find the term abbreviated as "regex" or "regexp". Regular expression is used for replacing a text within a string, validating form, extract a substring from a string based upon a pattern match, and so much more. -Imagine you are writing an application and you want to set the rules when user choosing their username. We want the username can -contains letter, number, underscore and hyphen. We also want to limit the number of characters in username so it does not look ugly. -We use the following regular expression to validate a username: +Imagine you are writing an application and you want to set the rules for when a user chooses their username. We want to +allow the username to contain letters, numbers, underscores and hyphens. We also want to limit the number of +characters in username so it does not look ugly. We use the following regular expression to validate a username:
@@ -59,7 +59,7 @@ contains uppercase letter and also it is too short. ## 1. Basic Matchers -A regular expression is just a pattern of letters and digits that we use to perform search in a text. For example, the regular expression +A regular expression is just a pattern of characters that we use to perform search in a text. For example, the regular expression `the` means: the letter `t`, followed by the letter `h`, followed by the letter `e`.
@@ -81,7 +81,7 @@ case-sensitive so the regular expression `The` would not match the string `the`. ## 2. Meta Characters Meta characters are the building blocks of the regular expressions. Meta characters do not stand for themselves but instead are -interpreted in some special way. Some meta characters have a special meaning that are written inside the square brackets. +interpreted in some special way. Some meta characters have a special meaning and are written inside square brackets. The meta characters are as follows: |Meta character|Description| @@ -271,9 +271,10 @@ expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by l ## 2.8 Anchors -In regular expressions, to check if the matching symbol is the starting symbol or ending symbol of the input string for this purpose -we use anchors. Anchors are of two types: First type is Caret `^` that check if the matching character is the start character of the -input and the second type is Dollar `$` that checks if matching character is the last character of the input string. +In regular expressions, we use anchors to check if the matching symbol is the starting symbol or ending symbol of the +input string. Anchors are of two types: First type is Caret `^` that check if the matching character is the start +character of the input and the second type is Dollar `$` that checks if matching character is the last character of the +input string. ### 2.8.1 Caret From 250d538b3c69668029f8f5e9688c9cb803d00a94 Mon Sep 17 00:00:00 2001 From: tldzyx+ +[正規表現の動作確認をする](https://regex101.com/r/IDDARt/1) + +### 4.2 否定的な先読み + +否定的な先読みはあるパターンが後続しない全てのマッチング文字列を取得するために使用します。 +否定的な先読みは肯定的な先読みと同じように定義しますが、 `=` の代わりに +`!` を使うところが唯一の違いで、`(?!...)` と記述します。 +次の正規表現 `[T|t]he(?!\sfat)` について考えてみます。 +これはスペースを挟んで `fat` が後続することがない全ての `The` または `the` を得ることができます。 + +Date: Sat, 12 Aug 2017 15:04:46 +0800 Subject: [PATCH 011/212] Update README-cn.md (#43) --- README-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-cn.md b/README-cn.md index 571aaaa1..483986c5 100644 --- a/README-cn.md +++ b/README-cn.md @@ -93,7 +93,7 @@ |[ ]|字符种类. 匹配方括号内的任意字符.| |[^ ]|否定的字符种类. 匹配除了方括号里的任意字符| |*|匹配>=0个重复的在*号之前的字符.| -|+|匹配>1个重复的+号前的字符. +|+|匹配>=1个重复的+号前的字符. |?|标记?之前的字符为可选.| |{n,m}|匹配num个中括号之前的字符 (n <= num <= m).| |(xyz)|字符集, 匹配与 xyz 完全相等的字符串.| From 22c68687553e3ee43ce8c1bff74e5346fb14f560 Mon Sep 17 00:00:00 2001 From: Kenichiro IDA Date: Mon, 14 Aug 2017 18:42:39 +0900 Subject: [PATCH 012/212] Translate to Japanese (#46) * Translate to Japanese * Modify anchors * Fix a typo * Fix a typo --- README-ja.md | 538 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 539 insertions(+) create mode 100644 README-ja.md diff --git a/README-ja.md b/README-ja.md new file mode 100644 index 00000000..991a46e8 --- /dev/null +++ b/README-ja.md @@ -0,0 +1,538 @@ +
++
+
+ +## 翻訳 + +* [English](README.md) +* [中文版](README-cn.md) +* [日本語](README-ja.md) + +## 正規表現とは + +> 正規表現とは文中からある文字列のパターンを見つけるために使用される文字列や記号の組み合わせのことです。 + +正規表現とは対象の文字列に左から右にマッチするパターンのことを言います。 +"Regular expression" (正規表現)という言葉は "regex" や "regexp" などと一言で言い表すことがあります。 +正規表現を使うことで文字列の置換・検証・抽出などを行うことが可能です。 + +アプリケーション中において、ユーザがユーザ名を決めるときに +守るべきルールを定義したいとしましょう。 +ユーザ名には文字・数字・アンダースコア・ハイフンが使用可能であるとします。 +また、ユーザ名が単調にならないように文字数にも制約を設けるものとします。 +この場合、次のような正規表現でユーザ名を検証することができます。 + +
++
+ +この正規表現によって `john_doe, jo-hn_doe, john12_as` などは許容されることになります。 +一方で `Jo` は大文字を含む上に短すぎるため許容されません。 + +## 目次 + +- [基本的な Matcher](#1-基本的な-matcher) +- [メタ文字](#2-メタ文字) + - [ピリオド](#21-ピリオド) + - [文字集合](#22-文字集合) + - [否定文字集合](#221-否定文字集合) + - [繰り返し](#23-繰り返し) + - [アスタリスク](#231-アスタリスク) + - [プラス記号](#232-プラス記号) + - [疑問符](#233-疑問符) + - [括弧](#24-括弧) + - [文字グループ](#25-文字グループ) + - [選言](#26-選言) + - [特殊文字をエスケープする](#27-特殊文字をエスケープする) + - [アンカー](#28-アンカー) + - [キャレット](#281-キャレット) + - [ドル記号](#282-ドル記号) +- [文字集合の短縮表記](#3-文字集合の短縮表記) +- [前後参照](#4-前後参照) + - [肯定的な先読み](#41-肯定的な先読み) + - [否定的な先読み](#42-否定的な先読み) + - [肯定的な後読み](#43-肯定的な後読み) + - [否定的な後読み](#44-否定的な後読み) +- [フラグ](#5-フラグ) + - [大文字・小文字を区別しない](#51-大文字・小文字を区別しない) + - [グローバル検索](#52-グローバル検索) + - [複数行](#53-複数行) +- [おまけ](#おまけ) + +## 1. 基本的な Matcher + +文中から特定の文字列を検索する時の正規表現は単なる文字の並びとして表されます。 +例えば `the` という正規表現は `t` という文字のあとに `h` が続き、さらに `e` が続くものだと +解釈されます。 + ++
+"the" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/dmRygT/1) + +`123` という正規表現は `123` という文字列にマッチします。 +正規表現は正規表現の文字列と入力文字列を1文字ずつ比較しながらマッチングを行います。 +また大文字と小文字は区別されるため、 `The` は `the` にはマッチしません。 + ++"The" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/1paXsy/1) + +## 2. メタ文字 + +メタ文字は正規表現の構成要素として使用される文字のことです。 +メタ文字はそれ自身が示す文字を表すものではなく、特別な解釈がなされます。 +一部のメタ文字は角括弧内に記述されることで特別な意味を持つものもあります。 +メタ文字には次のようなものがあります。 + +|メタ文字|説明 | +|:------:|---------------------------------------------------------------------------------------------| +|. |ピリオド。改行を除く任意の1文字にマッチ。 | +|[ ] |文字集合。角括弧内の任意の文字にマッチ。 | +|[^ ] |否定文字集合。角括弧内に含まれない任意の文字にマッチ。 | +|* |直前の文字の 0 個以上の並びにマッチ。 | +|+ |直前の文字の 1 個以上の並びにマッチ。 | +|? |直前の文字がオプションであるとみなす。 | +|{n,m} |括弧でくくる。直前の文字が n 個以上 m 個以下続く場合にマッチ。 | +|(xyz) |文字グループ。 xyz という文字列がその順に現れる場合にマッチ。 | +|| |選言。記号の前後の文字列どちらかにマッチ。 | +|\ |次に来る文字をエスケープする。予約語[ ] ( ) { } . * + ? ^ $ \ |にマッチ。| +|^ |入力値の開始にマッチする。 | +|$ |入力値の終了にマッチする。 | + +## 2.1 ピリオド + +ピリオド `.` は最もシンプルなメタ文字の例です。 +メタ文字 `.` は任意の 1 文字にマッチします。 +キャリッジリターンと改行にはマッチしません。 +例えば `.ar` は任意の文字の後に `a` と `r` が続く文字列にマッチします。 + ++".ar" => The car parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/xc9GkU/1) + +## 2.2 文字集合 + +文字集合は文字クラスとも呼ばれます。 +文字集合を指定するには角括弧でくくります。 +文字の範囲を指定するにはハイフンを使用します。 +角括弧内の文字の記述順はマッチングには関係ありません。 +例えば `[Tt]he` という正規表現は大文字 `T` または小文字 `t` の後に `h`, `e` が続く文字列を表します。 + ++"[Tt]he" => The car parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/2ITLQ4/1) + +文字集合内でのピリオドは文字としてのピリオドを表します。 +`ar[.]` という正規表現は `a` という文字のあとに `r` が続き、さらに `.` という文字が続く文字列を表します。 + ++"ar[.]" => A garage is a good place to park a car. ++ +[正規表現の動作確認をする](https://regex101.com/r/wL3xtE/1) + +### 2.2.1 否定文字集合 + +通常キャレットは文字列の開始を意味するメタ文字ですが、角括弧内で最初に使用されると +文字集合を否定する意味を持つようになります。 +例えば `[^c]ar` という正規表現は `c` 以外の任意の文字列の後に +`a`, `r` が続く文字列を表します。 + ++"[^c]ar" => The car parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/nNNlq3/1) + +## 2.3 繰り返し + +`+`, `*`, `?` はパターンが何回続くのかを指定するためのメタ文字になります。 +これらのメタ文字は異なるシチュエーションで異なる振る舞いをします。 + +### 2.3.1 アスタリスク + +シンボル `*` は直前の文字が 0 個以上続くパターンにマッチします。 +`a*` という正規表現は小文字の `a` が 0 個以上続くことを意味します。 +しかし文字集合またはクラスの後に現れた場合はその文字集合すべてが続くことを意味します。 +例えば `[a-z]*` という正規表現は行内の任意の小文字の列を表します。 + ++"[a-z]*" => The car parked in the garage #21. ++ +[正規表現の動作確認をする](https://regex101.com/r/7m8me5/1) + +シンボル `*` はメタ文字 `.` と合わせて `.*` のように使用することで +任意の文字列を表現できます。 +またスペースを表す `\s` と併用することで空白文字を表現できます。 +例えば `\s*cat\s*` という正規表現は 0 個以上のスペースの後に +小文字の `c`, `a`, `t` が続き、その後に 0 個以上のスペースが続きます。 + ++"\s*cat\s*" => The fat cat sat on the concatenation. ++ +[正規表現の動作確認をする](https://regex101.com/r/gGrwuz/1) + +### 2.3.2 プラス記号 + +シンボル `+` は直前の文字が 1 個以上続くパターンにマッチします。 +例えば `c.+t` という正規表現は小文字の `c` の後に +任意の 1 文字が続き、さらに `t` が続くことを意味します。 + ++"c.+t" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/Dzf9Aa/1) + +### 2.3.3 疑問符 + +正規表現におけるメタ文字 `?` は直前の文字がオプションであることを意味します。 +すなわち直前の文字が 0 個または 1 個現れることを意味します。 +例えば `[T]?he` という正規表現は大文字の `T` が 0 個または 1 個出現し、 +その後に小文字の `h`, `e` が続くことを意味します。 + ++"[T]he" => The car is parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/cIg9zm/1) + ++"[T]?he" => The car is parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/kPpO2x/1) + +## 2.4 括弧 + +正規表現における括弧は数量子とも呼ばれますが、文字列がいくつ現れるかを示すために使用されます。 +例えば、`[0-9]{2,3}` という正規表現は 2 桁以上 3 桁以下の数字 +(0 から 9 の数字で表された文字列)にマッチします。 + ++"[0-9]{2,3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[正規表現の動作確認をする](https://regex101.com/r/juM86s/1) + +2つ目の数値は省略できます。 +例えば `[0-9]{2,}` という正規表現は 2 桁以上の数字を意味します。 +カンマも省略することができ、その場合 `[0-9]{3}` という正規表現はちょうど 3 桁の数字を意味します。 + ++"[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[正規表現の動作確認をする](https://regex101.com/r/Gdy4w5/1) + ++"[0-9]{3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[正規表現の動作確認をする](https://regex101.com/r/Sivu30/1) + +## 2.5 文字グループ + +文字グループは括弧 `(...)` 内にパターンを記述してグループ分けをするために使用します。 +前述の通り、正規表現においては数量子を文字の後に置いた場合は +その直前の文字の繰り返しを意味します。しかし、文字グループの後に数量子を置いた場合は +文字グループ全体が繰り返すことを意味します。 +例えば、 `(ab)*` という正規表現は "ab" という文字列の 0 個以上の繰り返しにマッチします。 +文字グループ内では選言 `|` も使用することができます。 +例えば、`(c|g|p)ar` という正規表現は小文字の `c`, `g`, `p` のいずれかの後に +`a` が続き、さらに `r` が続くことを意味します。 + ++"(c|g|p)ar" => The car is parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/tUxrBG/1) + +## 2.6 選言 + +正規表現における縦棒 `|` は選言として使用されます。 +選言は複数の正規表現からなる条件式のようなものです。 +もしかすると文字集合と選言が同じものと感じるかもしれません。 +この 2 つの大きな違いは文字集合は文字単位で評価されるのに対して選言は正規表現単位で評価されます。 +例えば `(T|t)he|car` という正規表現は大文字の `T` または小文字の `t` の後に +小文字の `h`, `e` が続くか、または小文字の `c` の後に `a`, `r` が続くことを意味します。 + ++"(T|t)he|car" => The car is parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/fBXyX0/1) + +## 2.7 特殊文字をエスケープする + +バックスラッシュ `\` は正規表現内で次に来る文字をエスケープするために使用されます。 +これを使うと予約語 `{ } [ ] / \ + * . $ ^ | ?` を +記号として指定できるようになります。 +例えば `.` という正規表現は改行を除く任意の文字として使用されますが、 +`(f|c|m)at\.?` という正規表現では `.` 自体にマッチします。 +この正規表現は小文字の `f`, `c` または `m` の後に小文字の `a`, `t` が続き、 +さらに `.` が 0 個または 1 個続きます。 + ++"(f|c|m)at\.?" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/DOc5Nu/1) + +## 2.8 アンカー + +正規表現内でマッチング文字列の開始または終了であることをチェックするために +アンカーを使うことができます。 +アンカーには 2 種類あり、1 つ目が開始を表すキャレット `^`、 +2 つ目が終了を表すドル記号 `$` です。 + +### 2.8.1 キャレット + +キャレット `^` は文字列の開始かどうかを調べるために使用します。 +次の正規表現 `^a` は入力文字列 `abc` に対して(a が開始文字列なら)`a` にマッチします。 +しかし `^b` という正規表現は前の文字列に対してはどれにもマッチしません。 +"b" は `abc` という入力文字列の開始ではないからです。 +他の例を見てみます。`^(T|t)he` は大文字の `T` または小文字の `t` から始まる文字列で +その後に小文字の `h`, `e` が続くことを意味します。 + ++"(T|t)he" => The car is parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/5ljjgB/1) + ++"^(T|t)he" => The car is parked in the garage. ++ +[正規表現の動作確認をする](https://regex101.com/r/jXrKne/1) + +### 2.8.2 ドル記号 + +ドル記号 `$` は文字列の終了かどうかを調べるために使用します。 +例えば `(at\.)$` という正規表現は小文字の `a` の後に +小文字の `t` が続き、最後は `.` で終わることを意味しています。 + ++"(at\.)" => The fat cat. sat. on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/y4Au4D/1) + ++"(at\.)$" => The fat cat. sat. on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/t0AkOd/1) + +## 3. 文字集合の短縮表記 + +正規表現ではよく使われる文字集合に対して短縮表記が提供されており、 +便利なショートカットとして使用できます。 +省略表記には次のようなものがあります。 + +|短縮表記|説明 | +|:------:|-----------------------------------| +|. |改行を除く任意の文字 | +|\w |英数字にマッチ: `[a-zA-Z0-9_]` | +|\W |英数字以外にマッチ: `[^\w]` | +|\d |数字にマッチ: `[0-9]` | +|\D |数字以外にマッチ: `[^\d]` | +|\s |スペースにマッチ: `[\t\n\f\r\p{Z}]`| +|\S |スペース以外にマッチ: `[^\s]` | + +## 4. 前後参照 + +しばしば前後参照とも呼ばれる先読みと後読みは **非キャプチャグループ** +(パターンのマッチングはするがマッチングリストには含まれない)という +特殊な扱いがなされる機能です。 +前後参照はあるパターンが別のあるパターンよりも先行または後続して現れることを示すために使用されます。 +例えば入力文字列 `$4.44 and $10.88` に対して `$` に続く全ての数字を取得することを考えます。 +そのためには `(?<=\$)[0-9\.]*` という正規表現を使用します。 +これは `$` に続き `.` を含む全ての数字を指すことになります。 +次のような前後参照が正規表現で使用されます。 + +|記号 |説明 | +|:----:|--------------| +|?= |肯定的な先読み| +|?! |否定的な先読み| +|?<= |肯定的な後読み| +|? +"[T|t]he(?=\sfat)" => The fat cat sat on the mat. ++"[T|t]he(?!\sfat)" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/V32Npg/1) + +### 4.3 肯定的な後読み + +肯定的な後読みは特定のパターンが先行するような文字列を得るために使用します。 +定義の仕方は `(?<=...)` とします。 +例えば `(?<=[T|t]he\s)(fat|mat)` という正規表現は +`The` または `the` の後に続く全ての `fat` または `mat` が取得できます。 + ++"(?<=[T|t]he\s)(fat|mat)" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/avH165/1) + +### 4.4 否定的な後読み + +否定的な後読みは特定のパターンが先行しない全ての文字列を得るために使用します。 +定義の仕方は `(?)` とします。 +例えば `(? +"(?<![T|t]he\s)(cat)" => The cat sat on cat. ++"The" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/dpQyf9/1) + ++"/The/gi" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/ahfiuh/1) + +### 5.2 グローバル検索 + +修飾子 `g` はグローバル検索(最初のマッチ列を検索する代わりに全マッチ列を検索する)を +行うために使用します。 +例えば `/.(at)/g` という正規表現は、改行を除く任意の文字列の後に +小文字の `a`, `t` が続きます。正規表現の最後にフラグ `g` を渡すことで +入力文字列内の全マッチ列を検索するようにしています。 + ++"/.(at)/" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/jnk6gM/1) + ++"/.(at)/g" => The fat cat sat on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/dO1nef/1) + +### 5.3 複数行 + +修飾子 `m` は複数行でマッチさせたいときに使用します。 +前述で `(^, $)` という入力文字列の開始と終了を示すためのアンカーについて説明しましたが、 +フラグ `m` は複数行でマッチさせるためのアンカーとして使用できます。 +例えば `/at(.)?$/gm` という正規表現は小文字の `a`, `t` に続き、改行を除く +任意の文字が 0 個または 1 個続くという意味ですが、 +フラグ `m` を渡すことで入力文字列の各行でパターンを検索させることができます。 + ++"/.at(.)?$/" => The fat + cat sat + on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/hoGMkP/1) + ++"/.at(.)?$/gm" => The fat + cat sat + on the mat. ++ +[正規表現の動作確認をする](https://regex101.com/r/E88WE2/1) + +## おまけ + +* *正の整数*: `^\d+$` +* *負の整数*: `^-\d+$` +* *米国の電話番号*: `^+?[\d\s]{3,}$` +* *コード付きの米国の電話番号*: `^+?[\d\s]+(?[\d\s]{10,}$` +* *整数*: `^-?\d+$` +* *ユーザ名*: `^[\w.]{4,16}$` +* *英数字*: `^[a-zA-Z0-9]*$` +* *スペース込みの英数字*: `^[a-zA-Z0-9 ]*$` +* *パスワード*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` +* *Eメール*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})*$` +* *IPv4 アドレス*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` +* *小文字のみ*: `^([a-z])*$` +* *大文字のみ*: `^([A-Z])*$` +* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` +* *VISA クレジットカード番号*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` +* *日付 (DD/MM/YYYY)*: `^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$` +* *日付 (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` +* *日付 (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` +* *MasterCard クレジットカード番号*: `^(5[1-5][0-9]{14})*$` +* *ハッシュタグ*: 前の文字列を含む (abc123#xyz456) または角括弧内にスペースを含む (#[foo bar]) : `\S*#(?:\[[^\]]+\]|\S+)` +* *@mentions*: `\B@[a-z0-9_-]+` + +## 貢献する + +* 課題を発行する +* 修正をプルリクエストする +* ドキュメントを普及させる +* 作者に直接連絡を取る: ziishaned@gmail.com または [](https://twitter.com/ziishaned) + +## ライセンス + +MIT © [Zeeshan Ahmed](mailto:ziishaned@gmail.com) diff --git a/README.md b/README.md index 1df58ace..dff4b792 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ * [English](README.md) * [中文版](README-cn.md) +* [日本語](README-ja.md) ## What is Regular Expression? From 7b76a4a726c926ee28e7d98974fa7dca9d695ce7 Mon Sep 17 00:00:00 2001 From: Piper ChesterDate: Mon, 14 Aug 2017 09:41:02 -0400 Subject: [PATCH 013/212] README: 'new line' -> 'newline' (#47) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dff4b792..5627cfa5 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ The meta characters are as follows: ## 2.1 Full stop Full stop `.` is the simplest example of meta character. The meta character `.` matches any single character. It will not match return -or new line characters. For example, the regular expression `.ar` means: any character, followed by the letter `a`, followed by the +or newline characters. For example, the regular expression `.ar` means: any character, followed by the letter `a`, followed by the letter `r`. @@ -260,7 +260,7 @@ or lowercase character `c`, followed by lowercase character `a`, followed by low Backslash `\` is used in regular expression to escape the next character. This allows to to specify a symbol as a matching character including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it. -For example, the regular expression `.` is used to match any character except new line. Now to match `.` in an input string the regular +For example, the regular expression `.` is used to match any character except newline. Now to match `.` in an input string the regular expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase character `a`, followed by lowercase letter `t`, followed by optional `.` character. From ff3808ed94832e3a5c4176eee2be049e26f107eb Mon Sep 17 00:00:00 2001 From: binafor+ +[Prueba la expresión regular](https://regex101.com/r/IDDARt/1) + +### 4.2 Mirar hacia adelate negativa + +El lookahead negativo se usa cuando necesitamos obtener todas las coincidencias +de la cadena de entrada que no son seguidas por un patrón. El aspecto negativo se +define de la misma manera que definimos el aspecto positivo, pero la única diferencia +es que en lugar del caracter igual `=` utilizamos la negción `!` , es decir, +`(?! ...)`. Vamos a echar un vistazo a la siguiente expresión regular `[T|t]he(?!\Sfat)` +que significa: obtener todas las `The` o `the` seguidos por la palabra `fat` precedido por un carácter de espacio. + + +Date: Tue, 15 Aug 2017 11:18:41 +0800 Subject: [PATCH 014/212] fix typo (#49) --- README-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-cn.md b/README-cn.md index 483986c5..84cc721f 100644 --- a/README-cn.md +++ b/README-cn.md @@ -469,7 +469,7 @@ * *整数*: `^-?\d+$` * *用户名*: `^[\w\d_.]{4,16}$` * *数字和英文字母*: `^[a-zA-Z0-9]*$` -* *数字和应为字母和空格*: `^[a-zA-Z0-9 ]*$` +* *数字和英文字母和空格*: `^[a-zA-Z0-9 ]*$` * *密码*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` * *邮箱*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$` * *IP4 地址*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` From 02dd4cdb5310b6bc7fe89d0e8ac2bd59d81f30ae Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Wed, 16 Aug 2017 00:23:22 -0300 Subject: [PATCH 015/212] Add spanish version (#52) * [WIP] Add spanish version * Spanish translation finished. Ready for merge --- README-es.md | 483 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 138 +++++++-------- 2 files changed, 552 insertions(+), 69 deletions(-) create mode 100644 README-es.md diff --git a/README-es.md b/README-es.md new file mode 100644 index 00000000..24e86439 --- /dev/null +++ b/README-es.md @@ -0,0 +1,483 @@ +
++
+
+ +## Translations: + +* [English](README.md) +* [中文版](README-cn.md) +* [Español](README-es.md) + +## What is Regular Expression? +> Una expresión regular es un grupo de caracteres o símbolos, los cuales son usados para buscar un patrón específico dentro de un texto. + +Una expresión regular es un patrón que que se compara con una cadena de caracteres de izquierda a derecha. La palabra "expresión regular", puede también ser escrita como "Regex" o "Regexp". Las expresiones regulares se utiliza para remplazar un texto, dentro de un *string* (o cadena de caracteres), validar el formato, extraer un substring de un string completo basado en la coincidencia de una patrón, y muchas cosas más. + +Imagina que estas escribiendo una aplicación y quieres agregar reglas para cuando el usuario elija su nombre de usuario. Nosotros vamos a querer que el nombre de usuario contenga letras, números, guión bajo, y guíon medio. También vamos a querer limitar el número de caracteres en el nombre de usuario para que no se vea feo. Para ello usamos la siguiente expresión regular para validar el nombre de usuario + + +
++
+ +De la expresión regular anterior, se puede aceptar las cadenas 'john_doe', 'jo-hn_doe' y 'john12_as'. La expresión no coincide con el nombre de usuario 'Jo', porque es una cadena de caracteres que contiene letras mayúsculas y es demasiado corta. + +## Tabla de contenido + +- [Introducción](#1-introduccion) +- [Meta caracteres](#2-meta-caracteres) + - [Full stop](#21-full-stop) + - [Conjunto de caracteres](#22-conjunto-de-caracteres) + - [Conjunto de caracteres negados](#221-conjunto-de-caracteres-negado) + - [Repeticiones](#23-repeticiones) + - [Asterísco](#231-asterisco) + - [Signo más](#232-signo-mas) + - [Signo de pregunta](#233-signo-de-pregunta) + - [Llaves](#24-llaves) + - [Grupo de caracteres](#25-grupo-de-caracteres) + - [Alternancia](#26-alternacia) + - [Caracteres especiales de escape](#27-caracteres-especiales-de-escape) + - [Anclas](#28-anclas) + - [Símbolo de intercalación](#281-simbolo-de-intercalacion) + - [Símbolo dolar](#282-simbolo-dolar) +- [Conjunto de caracteres abreviados](#3-conjunto-de-caracteres-abreviados) +- [Mirar alrededor](#4-mirar-alrededor) + - [Mirar hacia delante positivo](#41-mirar-hacia-delante-positivo) + - [Mirar hacia delante negativo](#41-mirar-hacia-delaten-negativo) + - [Mirar hacia atrás positivo](#41-mirar-hacia-atras-positivo) + - [Mirar hacia atrás negativo](#41-mirar-hacia-atras-negativo) +- [Banderas](#5-banderas) + - [mayúsculas y minúsculas](#51-mayusculas-y-minusculas) + - [Búsqueda global](#52-busqueda-global) + - [Multilinea](#53-multilinea) +- [Bonus](#bonus) + +## 1. Introducción + +Una expresión regular es sólo un patrón de caracteres que utilizamos para realizar búsquedas en un texto. Por ejemplo, la expresión regular «the» significa: la letra `t` seguida de la letra `h` seguida de la letra `e`. + ++
+"the" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/dmRygT/1) + +La expresión regular `123` coincide con la cadena `123`. La expresión regular se compara con una cadena de entrada al comparar cada carácter de la expresión regular con cada carácter de la cadena de entrada, uno tras otro. Las expresiones regulares son normalmente sensibles a mayúsculas y minúsculas, por lo que la expresión regular `The` no coincide con la cadena `the`. + ++"The" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/1paXsy/1) + +## 2. Meta caracteres + +Los caracteres meta son los bloques de construcción de las expresiones regulares. Los meta caracteres no se sostienen a sí mismos, sino que se interpretan de alguna manera especial. Algunos meta caracteres tienen un significado especial y se escriben entre corchetes. Los meta caracteres son los siguientes: + +|Meta character|Description| +|:----:|----| +|.|Periodo. Coincide con cualquier caracter excepto un salto de línea.| +|[ ]|Clase caracter. Coincide con cualquier caracter contenido entre corchetes.| +|[^ ]|Clase caracter negado. Coincide con cualquier caracter que no está contenido dentro de los corchetes.| +|*|Corresponde con 0 o más repeticiones del símbolo precedente.| +|+|Corresponde con 1 o más repeticiones del símbolo precedente.| +|?|Hace que el símbolo precedente sea opcional.| +|{n,m}|Llaves.Corresponde al menos "n" pero no más de "m" repeticiones del símbolo precedente.| +|(xyz)|Grupo caracter. Hace coincidir los caracteres xyz en ese orden exacto.| +|||Alternancia. Corresponde a los caracteres anteriores o los caracteres después del símbolo.| +|\|Escapa el siguiente caracter. Esto le permite hacer coincidir los caracteres reservados[ ] ( ) { } . * + ? ^ $ \ || +|^|Hace coincidir el principio de la entrada.| +|$|Corresponde al final de la entrada.| + +## 2.1 Full stop + +Full stop `.` es el ejemplo más simple del meta-caracter. El caracter meta "." coincide con cualquier carácter. No coincidirá con el retorno o nuevos caracteres de línea. Por ejemplo, la expresión regular `.ar` significa: cualquier caracter, seguido de la letra`a`, seguido de la letra "r". + ++".ar" => The car parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/xc9GkU/1) + +## 2.2 Conjunto de caracteres + +Los conjuntos de caracteres también se llaman clase de caracteres. Los corchetes se utilizan para especificar conjuntos de caracteres. Utilice un guión dentro de un conjunto de caracteres para especificar el rango de los caracteres. El orden del rango de caracteres dentro de corchetes no importa. Por ejemplo, la expresión regular "[Tt] he" significa: una letra mayúscula "T" ot, seguida de la letra "h" seguida de la letra "e" + + +"[Tt]he" => The car parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/2ITLQ4/1) + +Sin embargo, un período dentro de un conjunto de caracteres significa un período literal. La expresión regular `ar [.]` Significa: un carácter minúsculo `a`, seguido de la letra` r`, seguido de un carácter `.`. + ++"ar[.]" => A garage is a good place to park a car. ++ +[Prueba la expresión regular](https://regex101.com/r/wL3xtE/1) + +### 2.2.1 Conjunto de caracteres negados + +En general, el símbolo de intercalación representa el comienzo de la cadena, pero cuando se escribe después del corchete de apertura niega el conjunto de caracteres. Por ejemplo, la expresión regular `[^c] ar` significa: cualquier carácter, excepto `c`, seguido del carácter `a`, seguido de la letra `r`. + ++"[^c]ar" => The car parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/nNNlq3/1) + +## 2.3 Repeticiones + +Siguiendo los caracteres meta +, * o ?, se utilizan para especificar cuántas veces puede producirse un subpatrón. Estos meta-caracteres actúan de manera diferente en diferentes situaciones. + +### 2.3.1 Asterísco + +El símbolo `*` coincide con cero o más repeticiones del marcador anterior. La expresión regular `a*` significa: cero o más repeticiones del carácter en minúscula precedente `a`. Pero si aparece después de un conjunto de caracteres o una clase, entonces encuentra las repeticiones de todo el conjunto de caracteres. Por ejemplo, la expresión regular `[a-z]*` significa: cualquier número de letras minúsculas en una fila. + ++"[a-z]*" => The car parked in the garage #21. ++ +[Prueba la expresión regular](https://regex101.com/r/7m8me5/1) + +El símbolo `*` se puede utilizar con el meta-caracter `.` para que coincida con cualquier cadena de caracteres `.*`. El símbolo `*` se lo puede utilizar con el caracter de espacio en blanco `\s` para que coincida con una cadena de caracteres de espacio en blanco. Por ejemplo, la expresión "\s*cat\s*" significa: cero o más espacios, seguido por el carácter en minúscula `c`, seguido del carácter en minúscula `a`, seguido del carácter en minúscula `t`, seguido de cero o más espacios. + ++"\s*cat\s*" => The fat cat sat on the concatenation. ++ +[Prueba la expresión regular](https://regex101.com/r/gGrwuz/1) + +### 2.3.2 Signo más + +El símbolo `+` coincide con una o más repeticiones del carácter anterior. Por ejemplo, la expresión regular `c.+T` significa: letra en minúscula `c`, seguida por al menos uno del mismo carácter, luego el carácter en minúscula `t`. + ++"c.+t" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/Dzf9Aa/1) + +### 2.3.3 Signo de pregunta + +En expresiones regulares el meta-caracter `?` hace que el caracter precedente sea opcional. Este símnbolo coincide con cero o una instancia del caracter precedente. Por ejemplo, la expresión regular `[T]?he` significa: El caracteropcional predecesor `T` seguido por la letra en minúscula `h`, seguido del caracter en minúscula `e`. + ++"[T]he" => The car is parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/cIg9zm/1) + ++"[T]?he" => The car is parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/kPpO2x/1) + +## 2.4 Llaves + +En la expresión regular, las llaves que también se denominan cuantificadores se utilizan para especificar el número de veces que se puede repetir un carácter o un grupo de caracteres. Por ejemplo, la expresión regular `[0-9]{2,3}` significa: Combina al menos 2 dígitos pero no más de 3 (caracteres del rango de 0 a 9). + ++"[0-9]{2,3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[Prueba la expresión regular](https://regex101.com/r/juM86s/1) + +Podemos dejar fuera el segundo número. Por ejemplo, la expresión regular `[0-9] {2,}` significa: Combina 2 o más dígitos. Si también eliminamos la coma, la expresión regular `[0-9]{3}` significa: coincidir exactamente con 3 dígitos. + ++"[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[Prueba la expresión regular](https://regex101.com/r/Gdy4w5/1) + ++"[0-9]{3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[Prueba la expresión regular](https://regex101.com/r/Sivu30/1) + +## 2.5 Grupos de caracteres + +Grupo de caracteres es un grupo de sub-patrones que se escribe dentro de paréntesis `(...)`. Como hemos discutido antes en la expresión regular si ponemos un cuantificador después de un caracter, repetiremos el caracter anterior. Pero si ponemos cuantificador después de un grupo de caracteres, entonces repetimos todo el grupo de caracteres. Por ejemplo, la expresión regular `(ab)*` coincide con cero o más repeticiones del caracter "ab". También podemos usar el caracter de alternancia `|` meta dentro del grupo de caracteres. Por ejemplo, la expresión regular `(c|g|p)ar` significa: caracter en minúscula `c`, `g` o `p`, seguido del caracter `a`, seguido del caracter `r`. ++"(c|g|p)ar" => The car is parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/tUxrBG/1) + +## 2.6 Alternancia + +En la expresión regular se usa la barra vertical `|` para definir la alternancia. La alternancia es como una condición entre múltiples expresiones. Ahora, puedes estar pensando que el conjunto de caracteres y la alternancia funciona de la misma manera. Pero la gran diferencia entre el conjunto de caracteres y la alternancia es que el conjunto de caracteres funciona a nivel de caracter pero la alternancia funciona a nivel de expresión. Por ejemplo, la expresión regular `(T|t)he|car` significa: el carcter en mayúscula `T` o en minúscula `t`, seguido del caracter en minúscula `h`, seguido del caracter en minúscula `e` o del caracter en minúscula `c`, seguido de un caracter en minúscula `a`, seguido del carácter en minúscula `r`. + ++"(T|t)he|car" => The car is parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/fBXyX0/1) + +## 2.7 Caracteres especiales de escape + +La barra invertida `\` se utiliza en la expresión regular para escapar del carácter siguiente. Esto permite especificar un símbolo como un caracter coincidente incluyendo caracteres reservados `{}[]/\+*.^|?`. Por ejemplo, la expresión regular `.` se utiliza para coincidir con cualquier caracter, excepto la nueva línea. Ahora, para emparejar `.` en una cadena de entrada, la expresión regular `(f|c|m)at\.?` significa: la letra minúscula `f`, `c` o `m`, seguida del caracter en minúscula `a`, seguido de la letra minúscula `t`, seguida del caracter opcional `.`. + ++"(f|c|m)at\.?" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/DOc5Nu/1) + +## 2.8 Anclas + +En expresiones regulares, usamos anclas para comprobar si el símbolo de coincidencia es el símbolo inicial o el símbolo final de la cadena de entrada. Los anclajes son de dos tipos: El primer tipo es el símbolo `^` que comprueba si el caracter coincidente es el caracter inicial de la entrada y el segundo tipo es Dollar `$` que comprueba si el caracter coincidente es el último caracter de la cadena de entrada. + +### 2.8.1 Simbolo de intercalación + +El símbolo de intercalación `^` se usa para verificar si el caracter coincidente es el primer caracter de la cadena de entrada. Si aplicamos la siguiente expresión regular `^a` (si a es el símbolo inicial) a la cadena de entrada `abc` coincide con `a`. Pero si aplicamos la expresión regular `^b` en la cadena de entrada anterior, no coincide con nada. Porque en la cadena de entrada `abc` "b" no es el símbolo inicial. Vamos a echar un vistazo a otra expresión regular `^(T|t)he`, significa: mayúsculas `T` o la letra minúscula `t` es el símbolo inicial de la cadena de entrada, seguido del caracter minúscula `h` y seguido del caracter en minúscula `e`. + ++"(T|t)he" => The car is parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/5ljjgB/1) + ++"^(T|t)he" => The car is parked in the garage. ++ +[Prueba la expresión regular](https://regex101.com/r/jXrKne/1) + +### 2.8.2 Símbolo dolar + +El símbolo de dólar `$` se utiliza para comprobar si el caracter coincidente es el último carácter de la cadena de entrada. Por ejemplo, la expresión regular `(at\.)$` significa: un caracter en minúscula `a`, seguido del caracter en minúscula `t` seguido de un carácter `.` y el marcador debe ser el final de la cadena. + ++"(at\.)" => The fat cat. sat. on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/y4Au4D/1) + ++"(at\.)$" => The fat cat. sat. on the mat. ++ +[Pueba la expresión regular](https://regex101.com/r/t0AkOd/1) + +## 3. Conjunto de caracteres abreviados + +La expresión regular proporciona abreviaturas para los conjuntos de caracteres +comúnmente utilizados, que ofrecen abreviaturas convenientes para expresiones +regulares de uso común. Los conjuntos de caracteres abreviados son los siguientes: + +|Shorthand|Description| +|:----:|----| +|.|Cualquier caracter excepto la nueva línea| +|\w|Coincide con los caracteres alfanuméricos: `[a-zA-Z0-9_]`| +|\W|Coincide con los caracteres no alfanuméricos: `[^\w]`| +|\d|Coincide con dígitos: `[0-9]`| +|\D|Coincide con no dígitos: `[^\d]`| +|\s|Coincide con caracteres espaciales: `[\t\n\f\r\p{Z}]`| +|\S|Coincide con caracteres no espaciales: `[^\s]`| + +## 4. Mirar alrededor + +Mirar hacia delante (lookaheds) y mirar hacia atrás (Lookbehind) a veces conocidos +como lookaround son tipo específico de ***grupo que no captura*** (Utilice para +coincidir con el patrón pero no se incluye en la lista correspondiente). Los +lookaheads se usan cuando tenemos la condición de que este patrón es precedido o +seguido por otro patrón determinado. Por ejemplo, queremos obtener todos los números +que están precedidos por el carácter `$` de la siguiente cadena de entrada +`$4.44 y $10.88`. Usaremos la siguiente expresión regular `(?<=\$)[0-9\.] *`, +esto significa: obtener todos los números que contienen el carácter `.` y +están precedidos del carácter `$`. A continuación se muestran los lookarounds +que se utilizan en expresiones regulares: + +|Symbol|Description| +|:----:|----| +|?=|Positive Lookahead| +|?!|Negative Lookahead| +|?<=|Positive Lookbehind| +|? +"[T|t]he(?=\sfat)" => The fat cat sat on the mat. ++"[T|t]he(?!\sfat)" => The fat cat sat on the mat. ++ +[Prueba la expresión](https://regex101.com/r/V32Npg/1) + +### 4.3 Mirar hacia atras positiva + +Positivo lookbehind se utiliza para obtener todos los caracteres que están precedidos +por un patrón específico. La apariencia positiva se denomina `(?<=...)`. +Por ejemplo, la expresión regular `(? <= [T|t]he\s)(fat|mat)` significa: obtener todas las palabras +`fat` o `mat` de la cadena de entrada después de la palabra `The` o `the`. + ++"(?<=[T|t]he\s)(fat|mat)" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/avH165/1) + +### 4.4 Mirar hacia atras negativa + +El lookbehind negativo se utiliza para obtener todas las coincidencias que no +están precedidas por un patrón específico. El lookbehind negativo se denota por +`(? +"(?<![T|t]he\s)(cat)" => The cat sat on cat. + + +[Prueba la expresión regular](https://regex101.com/r/8Efx5G/1) + +## 5. Banderas + +Los indicadores también se llaman modificadores porque modifican la salida +de una expresión regular. Estos indicadores se pueden utilizar en cualquier orden +o combinación, y son una parte integral de RegExp. + + +|Bandera|Descripción| +|:----:|----| +|i|Insensible a mayúsculas y minúsculas: ajusta la coincidencia para que no distinga mayúsculas y minúsculas.| +|g|Búsqueda global: busque un patrón en toda la cadena de entrada.| +|m|Multilinea: Ancla meta caracter trabaja en cada linea.| + +### 5.1 Mayúscula y minúscula + +El modificador `i` se utiliza para realizar la coincidencia entre mayúsculas y +minúsculas. Por ejemplo, la expresión regular `/The/gi` significa: letra mayúscula +`T`, seguido del caracter en minúscula `h`, seguido del carácter `e`. Y al final +de la expresión regular, el indicador `i` indica al motor de expresiones +regulares que ignore el caso. Como puede ver, también ofrecemos el indicador +`g` porque queremos buscar el patrón en toda la cadena de entrada. + + ++"The" => The fat cat sat on the mat. ++ +[Prueba la expresión regularn](https://regex101.com/r/dpQyf9/1) + ++"/The/gi" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/ahfiuh/1) + +### 5.2 Búsqueda global + +El modificador `g` se utiliza para realizar una coincidencia global +(encontrar todos las coincidencias en lugar de detenerse después de la primera coincidencia). +Por ejemplo, la expresión regular `/.(At)/g` significa: cualquier carácter, +excepto la nueva línea, seguido del caracter minúsculo `a`, seguido del caracter +en minúscula `t`. Debido a que siempre `g` prevee la bandera al final de la expresión +regular ahora encontrará todas las coincidencias de toda la cadena de entrada. + + ++"/.(at)/" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/jnk6gM/1) + ++"/.(at)/g" => The fat cat sat on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/dO1nef/1) + +### 5.3 Multilinea + +El modificador `m` se utiliza para realizar una coincidencia de varias líneas. +Como analizamos anteriormente, las anclas `(^,$)` se utilizan para comprobar si +el patrón es el comienzo de la entrada o el final de la cadena de entrada. Pero +si queremos que las anclas funcionen en cada línea usamos la bandera `m`. +Por ejemplo, la expresión regular `/at(.)?$/Gm` +significa: caracter en minúscula` a`, seguido del caracter minúsculo `t`, +opcionalmente cualquier cosa menos la nueva línea. Y debido a `m` bandera ahora +el motor de expresión regular coincide con el patrón al final de cada línea de una cadena. + ++"/.at(.)?$/" => The fat + cat sat + on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/hoGMkP/1) + ++"/.at(.)?$/gm" => The fat + cat sat + on the mat. ++ +[Prueba la expresión regular](https://regex101.com/r/E88WE2/1) + +## Bonus + +* *Positive Integers*: `^\d+$` +* *Negative Integers*: `^-\d+$` +* *US Phone Number*: `^+?[\d\s]{3,}$` +* *US Phone with code*: `^+?[\d\s]+(?[\d\s]{10,}$` +* *Integers*: `^-?\d+$` +* *Username*: `^[\w.]{4,16}$` +* *Alpha-numeric characters*: `^[a-zA-Z0-9]*$` +* *Alpha-numeric characters with spaces*: `^[a-zA-Z0-9 ]*$` +* *Password*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` +* *email*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})*$` +* *IPv4 address*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` +* *Lowercase letters only*: `^([a-z])*$` +* *Uppercase letters only*: `^([A-Z])*$` +* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` +* *VISA credit card numbers*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` +* *Date (DD/MM/YYYY)*: `^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$` +* *Date (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` +* *Date (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` +* *MasterCard credit card numbers*: `^(5[1-5][0-9]{14})*$` +* *Hashtags*: Including hashtags with preceding text (abc123#xyz456) or containing white spaces within square brackets (#[foo bar]) : `\S*#(?:\[[^\]]+\]|\S+)` +* *@mentions*: `\B@[a-z0-9_-]+` +## Contribution + +* Report issues +* Open pull request with improvements +* Spread the word +* Reach out to me directly at ziishaned@gmail.com or [](https://twitter.com/ziishaned) + +## License + +MIT © [Zeeshan Ahmed](mailto:ziishaned@gmail.com) diff --git a/README.md b/README.md index 5627cfa5..6ea79f70 100644 --- a/README.md +++ b/README.md @@ -11,24 +11,24 @@ ## What is Regular Expression? -> Regular expression is a group of characters or symbols which is used to find a specific pattern from a text. +> Regular expression is a group of characters or symbols which is used to find a specific pattern from a text. -A regular expression is a pattern that is matched against a subject string from left to right. The word "Regular expression" is a -mouthful, you will usually find the term abbreviated as "regex" or "regexp". Regular expression is used for replacing a text within +A regular expression is a pattern that is matched against a subject string from left to right. The word "Regular expression" is a +mouthful, you will usually find the term abbreviated as "regex" or "regexp". Regular expression is used for replacing a text within a string, validating form, extract a substring from a string based upon a pattern match, and so much more. -Imagine you are writing an application and you want to set the rules for when a user chooses their username. We want to -allow the username to contain letters, numbers, underscores and hyphens. We also want to limit the number of +Imagine you are writing an application and you want to set the rules for when a user chooses their username. We want to +allow the username to contain letters, numbers, underscores and hyphens. We also want to limit the number of characters in username so it does not look ugly. We use the following regular expression to validate a username:
-Above regular expression can accept the strings `john_doe`, `jo-hn_doe` and `john12_as`. It does not match `Jo` because that string +Above regular expression can accept the strings `john_doe`, `jo-hn_doe` and `john12_as`. It does not match `Jo` because that string contains uppercase letter and also it is too short. -## Table of Contents +## Table of Contents - [Basic Matchers](#1-basic-matchers) - [Meta character](#2-meta-characters) @@ -60,8 +60,8 @@ contains uppercase letter and also it is too short. ## 1. Basic Matchers -A regular expression is just a pattern of characters that we use to perform search in a text. For example, the regular expression -`the` means: the letter `t`, followed by the letter `h`, followed by the letter `e`. +A regular expression is just a pattern of characters that we use to perform search in a text. For example, the regular expression +`the` means: the letter `t`, followed by the letter `h`, followed by the letter `e`.
"the" => The fat cat sat on the mat. @@ -69,7 +69,7 @@ A regular expression is just a pattern of characters that we use to perform sear [Test the regular expression](https://regex101.com/r/dmRygT/1) -The regular expression `123` matches the string `123`. The regular expression is matched against an input string by comparing each +The regular expression `123` matches the string `123`. The regular expression is matched against an input string by comparing each character in the regular expression to each character in the input string, one after another. Regular expressions are normally case-sensitive so the regular expression `The` would not match the string `the`. @@ -81,8 +81,8 @@ case-sensitive so the regular expression `The` would not match the string `the`. ## 2. Meta Characters -Meta characters are the building blocks of the regular expressions. Meta characters do not stand for themselves but instead are -interpreted in some special way. Some meta characters have a special meaning and are written inside square brackets. +Meta characters are the building blocks of the regular expressions. Meta characters do not stand for themselves but instead are +interpreted in some special way. Some meta characters have a special meaning and are written inside square brackets. The meta characters are as follows: |Meta character|Description| @@ -114,8 +114,8 @@ letter `r`. ## 2.2 Character set -Character sets are also called character class. Square brackets are used to specify character sets. Use a hyphen inside a character set to -specify the characters' range. The order of the character range inside square brackets doesn't matter. For example, the regular +Character sets are also called character class. Square brackets are used to specify character sets. Use a hyphen inside a character set to +specify the characters' range. The order of the character range inside square brackets doesn't matter. For example, the regular expression `[Tt]he` means: an uppercase `T` or lowercase `t`, followed by the letter `h`, followed by the letter `e`.@@ -134,8 +134,8 @@ A period inside a character set, however, means a literal period. The regular ex ### 2.2.1 Negated character set -In general, the caret symbol represents the start of the string, but when it is typed after the opening square bracket it negates the -character set. For example, the regular expression `[^c]ar` means: any character except `c`, followed by the character `a`, followed by +In general, the caret symbol represents the start of the string, but when it is typed after the opening square bracket it negates the +character set. For example, the regular expression `[^c]ar` means: any character except `c`, followed by the character `a`, followed by the letter `r`.@@ -146,13 +146,13 @@ the letter `r`. ## 2.3 Repetitions -Following meta characters `+`, `*` or `?` are used to specify how many times a subpattern can occur. These meta characters act -differently in different situations. +Following meta characters `+`, `*` or `?` are used to specify how many times a subpattern can occur. These meta characters act +differently in different situations. ### 2.3.1 The Star -The symbol `*` matches zero or more repetitions of the preceding matcher. The regular expression `a*` means: zero or more repetitions -of preceding lowercase character `a`. But if it appears after a character set or class then it finds the repetitions of the whole +The symbol `*` matches zero or more repetitions of the preceding matcher. The regular expression `a*` means: zero or more repetitions +of preceding lowercase character `a`. But if it appears after a character set or class then it finds the repetitions of the whole character set. For example, the regular expression `[a-z]*` means: any number of lowercase letters in a row.@@ -161,9 +161,9 @@ character set. For example, the regular expression `[a-z]*` means: any number of [Test the regular expression](https://regex101.com/r/7m8me5/1) -The `*` symbol can be used with the meta character `.` to match any string of characters `.*`. The `*` symbol can be used with the -whitespace character `\s` to match a string of whitespace characters. For example, the expression `\s*cat\s*` means: zero or more -spaces, followed by lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `t`, followed by +The `*` symbol can be used with the meta character `.` to match any string of characters `.*`. The `*` symbol can be used with the +whitespace character `\s` to match a string of whitespace characters. For example, the expression `\s*cat\s*` means: zero or more +spaces, followed by lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `t`, followed by zero or more spaces.@@ -185,8 +185,8 @@ letter `c`, followed by at least one character, followed by the lowercase charac ### 2.3.3 The Question Mark -In regular expression the meta character `?` makes the preceding character optional. This symbol matches zero or one instance of -the preceding character. For example, the regular expression `[T]?he` means: Optional the uppercase letter `T`, followed by the lowercase +In regular expression the meta character `?` makes the preceding character optional. This symbol matches zero or one instance of +the preceding character. For example, the regular expression `[T]?he` means: Optional the uppercase letter `T`, followed by the lowercase character `h`, followed by the lowercase character `e`.@@ -203,7 +203,7 @@ character `h`, followed by the lowercase character `e`. ## 2.4 Braces -In regular expression braces that are also called quantifiers are used to specify the number of times that a +In regular expression braces that are also called quantifiers are used to specify the number of times that a character or a group of characters can be repeated. For example, the regular expression `[0-9]{2,3}` means: Match at least 2 digits but not more than 3 ( characters in the range of 0 to 9). @@ -213,7 +213,7 @@ characters in the range of 0 to 9). [Test the regular expression](https://regex101.com/r/juM86s/1) -We can leave out the second number. For example, the regular expression `[0-9]{2,}` means: Match 2 or more digits. If we also remove +We can leave out the second number. For example, the regular expression `[0-9]{2,}` means: Match 2 or more digits. If we also remove the comma the regular expression `[0-9]{3}` means: Match exactly 3 digits.@@ -230,10 +230,10 @@ the comma the regular expression `[0-9]{3}` means: Match exactly 3 digits. ## 2.5 Character Group -Character group is a group of sub-patterns that is written inside Parentheses `(...)`. As we discussed before that in regular expression -if we put a quantifier after a character then it will repeat the preceding character. But if we put quantifier after a character group then +Character group is a group of sub-patterns that is written inside Parentheses `(...)`. As we discussed before that in regular expression +if we put a quantifier after a character then it will repeat the preceding character. But if we put quantifier after a character group then it repeats the whole character group. For example, the regular expression `(ab)*` matches zero or more repetitions of the character "ab". -We can also use the alternation `|` meta character inside character group. For example, the regular expression `(c|g|p)ar` means: lowercase character `c`, +We can also use the alternation `|` meta character inside character group. For example, the regular expression `(c|g|p)ar` means: lowercase character `c`, `g` or `p`, followed by character `a`, followed by character `r`.@@ -244,10 +244,10 @@ We can also use the alternation `|` meta character inside character group. For e ## 2.6 Alternation -In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now, -you may be thinking that character set and alternation works the same way. But the big difference between character set and alternation -is that character set works on character level but alternation works on expression level. For example, the regular expression -`(T|t)he|car` means: uppercase character `T` or lowercase `t`, followed by lowercase character `h`, followed by lowercase character `e` +In regular expression Vertical bar `|` is used to define alternation. Alternation is like a condition between multiple expressions. Now, +you may be thinking that character set and alternation works the same way. But the big difference between character set and alternation +is that character set works on character level but alternation works on expression level. For example, the regular expression +`(T|t)he|car` means: uppercase character `T` or lowercase `t`, followed by lowercase character `h`, followed by lowercase character `e` or lowercase character `c`, followed by lowercase character `a`, followed by lowercase character `r`.@@ -272,17 +272,17 @@ expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by l ## 2.8 Anchors -In regular expressions, we use anchors to check if the matching symbol is the starting symbol or ending symbol of the -input string. Anchors are of two types: First type is Caret `^` that check if the matching character is the start -character of the input and the second type is Dollar `$` that checks if matching character is the last character of the +In regular expressions, we use anchors to check if the matching symbol is the starting symbol or ending symbol of the +input string. Anchors are of two types: First type is Caret `^` that check if the matching character is the start +character of the input and the second type is Dollar `$` that checks if matching character is the last character of the input string. ### 2.8.1 Caret -Caret `^` symbol is used to check if matching character is the first character of the input string. If we apply the following regular -expression `^a` (if a is the starting symbol) to input string `abc` it matches `a`. But if we apply regular expression `^b` on above -input string it does not match anything. Because in input string `abc` "b" is not the starting symbol. Let's take a look at another -regular expression `^(T|t)he` which means: uppercase character `T` or lowercase character `t` is the start symbol of the input string, +Caret `^` symbol is used to check if matching character is the first character of the input string. If we apply the following regular +expression `^a` (if a is the starting symbol) to input string `abc` it matches `a`. But if we apply regular expression `^b` on above +input string it does not match anything. Because in input string `abc` "b" is not the starting symbol. Let's take a look at another +regular expression `^(T|t)he` which means: uppercase character `T` or lowercase character `t` is the start symbol of the input string, followed by lowercase character `h`, followed by lowercase character `e`.@@ -299,8 +299,8 @@ followed by lowercase character `h`, followed by lowercase character `e`. ### 2.8.2 Dollar -Dollar `$` symbol is used to check if matching character is the last character of the input string. For example, regular expression -`(at\.)$` means: a lowercase character `a`, followed by lowercase character `t`, followed by a `.` character and the matcher +Dollar `$` symbol is used to check if matching character is the last character of the input string. For example, regular expression +`(at\.)$` means: a lowercase character `a`, followed by lowercase character `t`, followed by a `.` character and the matcher must be end of the string.@@ -317,7 +317,7 @@ must be end of the string. ## 3. Shorthand Character Sets -Regular expression provides shorthands for the commonly used character sets, which offer convenient shorthands for commonly used +Regular expression provides shorthands for the commonly used character sets, which offer convenient shorthands for commonly used regular expressions. The shorthand character sets are as follows: |Shorthand|Description| @@ -332,10 +332,10 @@ regular expressions. The shorthand character sets are as follows: ## 4. Lookaround -Lookbehind and lookahead sometimes known as lookaround are specific type of ***non-capturing group*** (Use to match the pattern but not -included in matching list). Lookaheads are used when we have the condition that this pattern is preceded or followed by another certain -pattern. For example, we want to get all numbers that are preceded by `$` character from the following input string `$4.44 and $10.88`. -We will use following regular expression `(?<=\$)[0-9\.]*` which means: get all the numbers which contain `.` character and are preceded +Lookbehind and lookahead sometimes known as lookaround are specific type of ***non-capturing group*** (Use to match the pattern but not +included in matching list). Lookaheads are used when we have the condition that this pattern is preceded or followed by another certain +pattern. For example, we want to get all numbers that are preceded by `$` character from the following input string `$4.44 and $10.88`. +We will use following regular expression `(?<=\$)[0-9\.]*` which means: get all the numbers which contain `.` character and are preceded by `$` character. Following are the lookarounds that are used in regular expressions: |Symbol|Description| @@ -348,11 +348,11 @@ by `$` character. Following are the lookarounds that are used in regular express ### 4.1 Positive Lookahead The positive lookahead asserts that the first part of the expression must be followed by the lookahead expression. The returned match -only contains the text that is matched by the first part of the expression. To define a positive lookahead, parentheses are used. Within -those parentheses, a question mark with equal sign is used like this: `(?=...)`. Lookahead expression is written after the equal sign inside -parentheses. For example, the regular expression `[T|t]he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase letter `T`, +only contains the text that is matched by the first part of the expression. To define a positive lookahead, parentheses are used. Within +those parentheses, a question mark with equal sign is used like this: `(?=...)`. Lookahead expression is written after the equal sign inside +parentheses. For example, the regular expression `[T|t]he(?=\sfat)` means: optionally match lowercase letter `t` or uppercase letter `T`, followed by letter `h`, followed by letter `e`. In parentheses we define positive lookahead which tells regular expression engine to match -`The` or `the` which are followed by the word `fat`. +`The` or `the` which are followed by the word `fat`."[T|t]he(?=\sfat)" => The fat cat sat on the mat. @@ -362,9 +362,9 @@ followed by letter `h`, followed by letter `e`. In parentheses we define positiv ### 4.2 Negative Lookahead -Negative lookahead is used when we need to get all matches from input string that are not followed by a pattern. Negative lookahead -defined same as we define positive lookahead but the only difference is instead of equal `=` character we use negation `!` character -i.e. `(?!...)`. Let's take a look at the following regular expression `[T|t]he(?!\sfat)` which means: get all `The` or `the` words from +Negative lookahead is used when we need to get all matches from input string that are not followed by a pattern. Negative lookahead +defined same as we define positive lookahead but the only difference is instead of equal `=` character we use negation `!` character +i.e. `(?!...)`. Let's take a look at the following regular expression `[T|t]he(?!\sfat)` which means: get all `The` or `the` words from input string that are not followed by the word `fat` precedes by a space character.@@ -375,8 +375,8 @@ input string that are not followed by the word `fat` precedes by a space charact ### 4.3 Positive Lookbehind -Positive lookbehind is used to get all the matches that are preceded by a specific pattern. Positive lookbehind is denoted by -`(?<=...)`. For example, the regular expression `(?<=[T|t]he\s)(fat|mat)` means: get all `fat` or `mat` words from input string that +Positive lookbehind is used to get all the matches that are preceded by a specific pattern. Positive lookbehind is denoted by +`(?<=...)`. For example, the regular expression `(?<=[T|t]he\s)(fat|mat)` means: get all `fat` or `mat` words from input string that are after the word `The` or `the`.@@ -387,8 +387,8 @@ are after the word `The` or `the`. ### 4.4 Negative Lookbehind -Negative lookbehind is used to get all the matches that are not preceded by a specific pattern. Negative lookbehind is denoted by -`(? @@ -399,7 +399,7 @@ are not after the word `The` or `the`. ## 5. Flags -Flags are also called modifiers because they modify the output of a regular expression. These flags can be used in any order or +Flags are also called modifiers because they modify the output of a regular expression. These flags can be used in any order or combination, and are an integral part of the RegExp. |Flag|Description| @@ -410,9 +410,9 @@ combination, and are an integral part of the RegExp. ### 5.1 Case Insensitive -The `i` modifier is used to perform case-insensitive matching. For example, the regular expression `/The/gi` means: uppercase letter -`T`, followed by lowercase character `h`, followed by character `e`. And at the end of regular expression the `i` flag tells the -regular expression engine to ignore the case. As you can see we also provided `g` flag because we want to search for the pattern in +The `i` modifier is used to perform case-insensitive matching. For example, the regular expression `/The/gi` means: uppercase letter +`T`, followed by lowercase character `h`, followed by character `e`. And at the end of regular expression the `i` flag tells the +regular expression engine to ignore the case. As you can see we also provided `g` flag because we want to search for the pattern in the whole input string.@@ -429,9 +429,9 @@ the whole input string. ### 5.2 Global search -The `g` modifier is used to perform a global match (find all matches rather than stopping after the first match). For example, the -regular expression`/.(at)/g` means: any character except new line, followed by lowercase character `a`, followed by lowercase -character `t`. Because we provided `g` flag at the end of the regular expression now it will find every matches from whole input +The `g` modifier is used to perform a global match (find all matches rather than stopping after the first match). For example, the +regular expression`/.(at)/g` means: any character except new line, followed by lowercase character `a`, followed by lowercase +character `t`. Because we provided `g` flag at the end of the regular expression now it will find every matches from whole input string.@@ -448,9 +448,9 @@ string. ### 5.3 Multiline -The `m` modifier is used to perform a multi-line match. As we discussed earlier anchors `(^, $)` are used to check if pattern is +The `m` modifier is used to perform a multi-line match. As we discussed earlier anchors `(^, $)` are used to check if pattern is the beginning of the input or end of the input string. But if we want that anchors works on each line we use `m` flag. For example, the -regular expression `/at(.)?$/gm` means: lowercase character `a`, followed by lowercase character `t`, optionally anything except new +regular expression `/at(.)?$/gm` means: lowercase character `a`, followed by lowercase character `t`, optionally anything except new line. And because of `m` flag now regular expression engine matches pattern at the end of each line in a string.@@ -496,7 +496,7 @@ line. And because of `m` flag now regular expression engine matches pattern at t * Report issues * Open pull request with improvements -* Spread the word +* Spread the word * Reach out to me directly at ziishaned@gmail.com or [](https://twitter.com/ziishaned) ## License From 4158a0385fd02413d1e1575e59e9bf3cea2f8ad6 Mon Sep 17 00:00:00 2001 From: Zeeshan AhmedDate: Wed, 16 Aug 2017 08:26:23 +0500 Subject: [PATCH 016/212] Update translations in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6ea79f70..20467178 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ ## Translations: * [English](README.md) +* [Spanish](README-es.md) * [中文版](README-cn.md) * [日本語](README-ja.md) From 4ab2af3c4cb24ff10cc6d8271480dc6ff5756fa4 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 08:27:43 +0500 Subject: [PATCH 017/212] Update translations link --- README-cn.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README-cn.md b/README-cn.md index 84cc721f..9769e30a 100644 --- a/README-cn.md +++ b/README-cn.md @@ -6,7 +6,9 @@ ## 翻译: * [English](README.md) +* [Spanish](README-es.md) * [中文版](README-cn.md) +* [日本語](README-ja.md) ## 什么是正则表达式? From fa9da320c9710337c40305ffa66bab9ca2e51b9e Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 08:29:05 +0500 Subject: [PATCH 018/212] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20467178..5cd85388 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Translations: * [English](README.md) -* [Spanish](README-es.md) +* [Español](README-es.md) * [中文版](README-cn.md) * [日本語](README-ja.md) From 070093d1e6253b716461d1e744c39996118e03cc Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 08:29:24 +0500 Subject: [PATCH 019/212] Update README-es.md --- README-es.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README-es.md b/README-es.md index 24e86439..42a10d2c 100644 --- a/README-es.md +++ b/README-es.md @@ -6,8 +6,9 @@ ## Translations: * [English](README.md) +* [Español](README-es.md) * [中文版](README-cn.md) -* [Español](README-es.md) +* [日本語](README-ja.md) ## What is Regular Expression? > Una expresión regular es un grupo de caracteres o símbolos, los cuales son usados para buscar un patrón específico dentro de un texto. From 8cb2f7d6cdf25bfec66e631c1fe8372ea66db3b7 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 08:29:42 +0500 Subject: [PATCH 020/212] Update README-ja.md --- README-ja.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README-ja.md b/README-ja.md index 991a46e8..ba89c02f 100644 --- a/README-ja.md +++ b/README-ja.md @@ -6,6 +6,7 @@ ## 翻訳 * [English](README.md) +* [Español](README-es.md) * [中文版](README-cn.md) * [日本語](README-ja.md) From 94c90e66c35ad539e472e102dd313fbe612a4df7 Mon Sep 17 00:00:00 2001 From: Alex Sun Date: Wed, 16 Aug 2017 19:38:18 +0800 Subject: [PATCH 021/212] fix format (#55) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit replace `~` with `~` to avoid incorrect format --- README-cn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-cn.md b/README-cn.md index 9769e30a..34d42e0f 100644 --- a/README-cn.md +++ b/README-cn.md @@ -206,7 +206,7 @@ ## 2.4 `{}` 号 在正则表达式中 `{}` 是一个量词, 常用来一个或一组字符可以重复出现的次数. -例如, 表达式 `[0-9]{2,3}` 匹配 2~3 位 0~9 的数字. +例如, 表达式 `[0-9]{2,3}` 匹配 2~3 位 0~9 的数字. From 3cb7983839280fd3c1126d77b1b2adff9097f4d8 Mon Sep 17 00:00:00 2001 From: AbelDate: Wed, 16 Aug 2017 19:43:26 +0800 Subject: [PATCH 022/212] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=AF=91=E6=96=87=20(#56)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update README-cn.md * Update README-cn.md --- README-cn.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README-cn.md b/README-cn.md index 34d42e0f..97725f6c 100644 --- a/README-cn.md +++ b/README-cn.md @@ -16,8 +16,8 @@ 一个正则表达式是在一个主体字符串中从左到右匹配字符串时的一种样式. -例如"Regular expression"是一个完整的句子, 但我们常使用缩写的术语"regex"或"regexp". -正则表达式可以用来替换文本中的字符串,验证形式,提取字符串等等. +"Regular expression"这个词比较拗口, 我们常使用缩写的术语"regex"或"regexp". +正则表达式可以从一个基础字符串中根据一定的匹配模式替换文本中的字符串、验证表单、提取字符串等等. 想象你正在写一个应用, 然后你想设定一个用户命名的规则, 让用户名包含字符,数字,下划线和连字符,以及限制字符的个数,好让名字看起来没那么丑. 我们使用以下正则表达式来验证一个用户名: From 499de93acd05e4f63a5d45d698595bd571ce799d Mon Sep 17 00:00:00 2001 From: AndyZ Date: Wed, 16 Aug 2017 19:51:08 +0800 Subject: [PATCH 023/212] Something really need to be clarified (#48) * Something really need to be clarified the `+` is tricky * add explanation on the optional ? Thanks for the great project , hope this can help to clarify a bit in Chinese * Change a bit on . some typo corrected --- README-cn.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README-cn.md b/README-cn.md index 97725f6c..8306e36d 100644 --- a/README-cn.md +++ b/README-cn.md @@ -261,7 +261,7 @@ 反斜线 `\` 在表达式中用于转码紧跟其后的字符. 用于指定 `{ } [ ] / \ + * . $ ^ | ?` 这些特殊字符. 如果想要匹配这些特殊字符则要在其前面加上反斜线 `\`. -例如 `.` 是用来匹配除换行符外的所有字符的. 如果想要匹配句子中的 `.` 则要写成 `\.`. +例如 `.` 是用来匹配除换行符外的所有字符的. 如果想要匹配句子中的 `.` 则要写成 `\.` 以下这个例子 `\.?`是选择性匹配`.` "(f|c|m)at\.?" => The fat cat sat on the mat. diff --git a/README.md b/README.md index 5cd85388..fa8e6750 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ zero or more spaces. ### 2.3.2 The Plus The symbol `+` matches one or more repetitions of the preceding character. For example, the regular expression `c.+t` means: lowercase -letter `c`, followed by at least one character, followed by the lowercase character `t`. +letter `c`, followed by at least one character, followed by the lowercase character `t`. It needs to be clarified that `t` is the last `t` in the sentence."c.+t" => The fat cat sat on the mat. From 2375040f554549de998b9d22994ab11a44c46caa Mon Sep 17 00:00:00 2001 From: Zeeshan AhmedDate: Wed, 16 Aug 2017 16:55:28 +0500 Subject: [PATCH 024/212] Update README.md --- README.md | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/README.md b/README.md index fa8e6750..31cd31cd 100644 --- a/README.md +++ b/README.md @@ -470,29 +470,6 @@ line. And because of `m` flag now regular expression engine matches pattern at t [Test the regular expression](https://regex101.com/r/E88WE2/1) -## Bonus - -* *Positive Integers*: `^\d+$` -* *Negative Integers*: `^-\d+$` -* *US Phone Number*: `^+?[\d\s]{3,}$` -* *US Phone with code*: `^+?[\d\s]+(?[\d\s]{10,}$` -* *Integers*: `^-?\d+$` -* *Username*: `^[\w.]{4,16}$` -* *Alpha-numeric characters*: `^[a-zA-Z0-9]*$` -* *Alpha-numeric characters with spaces*: `^[a-zA-Z0-9 ]*$` -* *Password*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` -* *email*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})*$` -* *IPv4 address*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` -* *Lowercase letters only*: `^([a-z])*$` -* *Uppercase letters only*: `^([A-Z])*$` -* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` -* *VISA credit card numbers*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` -* *Date (DD/MM/YYYY)*: `^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$` -* *Date (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` -* *Date (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` -* *MasterCard credit card numbers*: `^(5[1-5][0-9]{14})*$` -* *Hashtags*: Including hashtags with preceding text (abc123#xyz456) or containing white spaces within square brackets (#[foo bar]) : `\S*#(?:\[[^\]]+\]|\S+)` -* *@mentions*: `\B@[a-z0-9_-]+` ## Contribution * Report issues From b266e64b60c7709b5bef96abbb04c07f74478f33 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 16:56:06 +0500 Subject: [PATCH 025/212] Update README-ja.md --- README-ja.md | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/README-ja.md b/README-ja.md index ba89c02f..fe039ead 100644 --- a/README-ja.md +++ b/README-ja.md @@ -503,30 +503,6 @@ [正規表現の動作確認をする](https://regex101.com/r/E88WE2/1) -## おまけ - -* *正の整数*: `^\d+$` -* *負の整数*: `^-\d+$` -* *米国の電話番号*: `^+?[\d\s]{3,}$` -* *コード付きの米国の電話番号*: `^+?[\d\s]+(?[\d\s]{10,}$` -* *整数*: `^-?\d+$` -* *ユーザ名*: `^[\w.]{4,16}$` -* *英数字*: `^[a-zA-Z0-9]*$` -* *スペース込みの英数字*: `^[a-zA-Z0-9 ]*$` -* *パスワード*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` -* *Eメール*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})*$` -* *IPv4 アドレス*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` -* *小文字のみ*: `^([a-z])*$` -* *大文字のみ*: `^([A-Z])*$` -* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` -* *VISA クレジットカード番号*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` -* *日付 (DD/MM/YYYY)*: `^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$` -* *日付 (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` -* *日付 (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` -* *MasterCard クレジットカード番号*: `^(5[1-5][0-9]{14})*$` -* *ハッシュタグ*: 前の文字列を含む (abc123#xyz456) または角括弧内にスペースを含む (#[foo bar]) : `\S*#(?:\[[^\]]+\]|\S+)` -* *@mentions*: `\B@[a-z0-9_-]+` - ## 貢献する * 課題を発行する From fc0548d940e6512dffb39166939fd14a643065a6 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 16:57:07 +0500 Subject: [PATCH 026/212] Update README-es.md --- README-es.md | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/README-es.md b/README-es.md index 42a10d2c..64ca5965 100644 --- a/README-es.md +++ b/README-es.md @@ -449,29 +449,6 @@ el motor de expresión regular coincide con el patrón al final de cada línea d [Prueba la expresión regular](https://regex101.com/r/E88WE2/1) -## Bonus - -* *Positive Integers*: `^\d+$` -* *Negative Integers*: `^-\d+$` -* *US Phone Number*: `^+?[\d\s]{3,}$` -* *US Phone with code*: `^+?[\d\s]+(?[\d\s]{10,}$` -* *Integers*: `^-?\d+$` -* *Username*: `^[\w.]{4,16}$` -* *Alpha-numeric characters*: `^[a-zA-Z0-9]*$` -* *Alpha-numeric characters with spaces*: `^[a-zA-Z0-9 ]*$` -* *Password*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` -* *email*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})*$` -* *IPv4 address*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` -* *Lowercase letters only*: `^([a-z])*$` -* *Uppercase letters only*: `^([A-Z])*$` -* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` -* *VISA credit card numbers*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` -* *Date (DD/MM/YYYY)*: `^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}$` -* *Date (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` -* *Date (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` -* *MasterCard credit card numbers*: `^(5[1-5][0-9]{14})*$` -* *Hashtags*: Including hashtags with preceding text (abc123#xyz456) or containing white spaces within square brackets (#[foo bar]) : `\S*#(?:\[[^\]]+\]|\S+)` -* *@mentions*: `\B@[a-z0-9_-]+` ## Contribution * Report issues From 9368d09838e4e39a350b48505cb0b8fb331503e2 Mon Sep 17 00:00:00 2001 From: Zeeshan Ahmed Date: Wed, 16 Aug 2017 16:57:45 +0500 Subject: [PATCH 027/212] Update README-cn.md --- README-cn.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/README-cn.md b/README-cn.md index 8306e36d..e075d23a 100644 --- a/README-cn.md +++ b/README-cn.md @@ -462,27 +462,6 @@ [在线练习](https://regex101.com/r/E88WE2/1) -## 额外补充 - -* *正整数*: `^\d+$` -* *负整数*: `^-\d+$` -* *手机国家号*: `^+?[\d\s]{3,}$` -* *手机号*: `^+?[\d\s]+(?[\d\s]{10,}$` -* *整数*: `^-?\d+$` -* *用户名*: `^[\w\d_.]{4,16}$` -* *数字和英文字母*: `^[a-zA-Z0-9]*$` -* *数字和英文字母和空格*: `^[a-zA-Z0-9 ]*$` -* *密码*: `^(?=^.{6,}$)((?=.*[A-Za-z0-9])(?=.*[A-Z])(?=.*[a-z]))^.*$` -* *邮箱*: `^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})*$` -* *IP4 地址*: `^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$` -* *纯小写字母*: `^([a-z])*$` -* *纯大写字母*: `^([A-Z])*$` -* *URL*: `^(((http|https|ftp):\/\/)?([[a-zA-Z0-9]\-\.])+(\.)([[a-zA-Z0-9]]){2,4}([[a-zA-Z0-9]\/+=%&_\.~?\-]*))*$` -* *VISA 信用卡号*: `^(4[0-9]{12}(?:[0-9]{3})?)*$` -* *日期 (MM/DD/YYYY)*: `^(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}$` -* *日期 (YYYY/MM/DD)*: `^(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])$` -* *MasterCard 信用卡号*: `^(5[1-5][0-9]{14})*$` - ## 贡献 * 报告问题 From ea270ac1e399fc50b1905adf359a577bbbc2e2cf Mon Sep 17 00:00:00 2001 From: chroju Date: Thu, 17 Aug 2017 01:09:39 +0900 Subject: [PATCH 028/212] Fix typos (#57) --- README-ja.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README-ja.md b/README-ja.md index fe039ead..523928ea 100644 --- a/README-ja.md +++ b/README-ja.md @@ -189,7 +189,7 @@ シンボル `+` は直前の文字が 1 個以上続くパターンにマッチします。 例えば `c.+t` という正規表現は小文字の `c` の後に -任意の 1 文字が続き、さらに `t` が続くことを意味します。 +任意の 1 文字以上が続き、さらに `t` が続くことを意味します。 "c.+t" => The fat cat sat on the mat. @@ -342,7 +342,7 @@ 正規表現ではよく使われる文字集合に対して短縮表記が提供されており、 便利なショートカットとして使用できます。 -省略表記には次のようなものがあります。 +短縮表記には次のようなものがあります。 |短縮表記|説明 | |:------:|-----------------------------------| @@ -441,7 +441,7 @@ ### 5.1 大文字・小文字を区別しない -修飾子 `i` は大文字・小文字を区別しなくないときに使用します。 +修飾子 `i` は大文字・小文字を区別したくないときに使用します。 例えば `/The/gi` という正規表現は大文字の `T` の後に小文字の `h`, `e` が続くという意味ですが、 最後の `i` で大文字・小文字を区別しない設定にしています。 文字列内の全マッチ列を検索したいのでフラグ `g` も渡しています。 @@ -505,7 +505,7 @@ ## 貢献する -* 課題を発行する +* イシューを発行する * 修正をプルリクエストする * ドキュメントを普及させる * 作者に直接連絡を取る: ziishaned@gmail.com または [](https://twitter.com/ziishaned) From e698d5da285e08426f01d1bf49b627b3ef1403f8 Mon Sep 17 00:00:00 2001 From: MayurDate: Thu, 17 Aug 2017 15:58:54 +0530 Subject: [PATCH 029/212] FIX typo in Escaping special character section (#63) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 31cd31cd..3fde9403 100644 --- a/README.md +++ b/README.md @@ -259,7 +259,7 @@ or lowercase character `c`, followed by lowercase character `a`, followed by low ## 2.7 Escaping special character -Backslash `\` is used in regular expression to escape the next character. This allows to to specify a symbol as a matching character +Backslash `\` is used in regular expression to escape the next character. This allows us to specify a symbol as a matching character including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it. For example, the regular expression `.` is used to match any character except newline. Now to match `.` in an input string the regular expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase character `a`, followed by lowercase letter From 9483a3fa16268b43979e5428db5b80a6663be09f Mon Sep 17 00:00:00 2001 From: Sahib Yar Date: Thu, 17 Aug 2017 15:29:42 +0500 Subject: [PATCH 030/212] deleted the bonus from table of contents (#62) As you now you have removed the bonus section, which contained the examples, the bonus tag should be removed from the table of contents also. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3fde9403..ece50f70 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ contains uppercase letter and also it is too short. - [Case Insensitive](#51-case-insensitive) - [Global search](#52-global-search) - [Multiline](#53-multiline) -- [Bonus](#bonus) ## 1. Basic Matchers From 7ddb3f6bf5556aa62d67ab6fee8fb4091ee5a9ab Mon Sep 17 00:00:00 2001 From: Allan Date: Fri, 18 Aug 2017 10:11:36 +0800 Subject: [PATCH 031/212] Add some compatible character set (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改一处错别字 添加部分简写字符集 --- README-cn.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README-cn.md b/README-cn.md index e075d23a..2fbcee53 100644 --- a/README-cn.md +++ b/README-cn.md @@ -277,7 +277,7 @@ `^` 用来检查匹配的字符串是否在所匹配字符串的开头. -例如, 在 `abc` 中使用表达式 `^a` 会得到结果 `a`. 但如果使用 `^b` 将匹配不到任何结果. 应为在字符串 `abc` 中并不是以 `b` 开头. +例如, 在 `abc` 中使用表达式 `^a` 会得到结果 `a`. 但如果使用 `^b` 将匹配不到任何结果. 因为在字符串 `abc` 中并不是以 `b` 开头. 例如, `^(T|t)he` 匹配以 `The` 或 `the` 开头的字符串. @@ -324,6 +324,12 @@ |\D|匹配非数字: `[^\d]`| |\s|匹配所有空格字符, 等同于: `[\t\n\f\r\p{Z}]`| |\S|匹配所有非空格字符: `[^\s]`| +|\f|匹配一个换页符| +|\n|匹配一个换行符| +|\r|匹配一个回车符| +|\t|匹配一个制表符| +|\v|匹配一个垂直制表符| +|\p|匹配 CR/LF (等同于 `\r\n`),用来匹配 DOS 行终止符| ## 4. 前后关联约束(前后预查) From e67ac5d408e36e8403b3682548a0c41e3e39bec9 Mon Sep 17 00:00:00 2001 From: Loic Humbert Date: Fri, 18 Aug 2017 18:16:07 +0200 Subject: [PATCH 032/212] French translation (#59) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * created file for translation * Added french link * Intro translated * Intro translated * §1 * §2 * Titles translated * §2.1 * Fixed tick issue in title star * Fixed tick issue in title star * §2.2 * Fixed multilignes link * Organized language choice * §2.2.1 * 2.3 => 2.3.1 * §2.3.2 * §2.3.3 * §2.7 * 2.4 => 2.7 * 2.8.1 * 2.8.2 => 4 * 4.2 => 4.3 * 4.4 * changed 'Recherche globale' to 'Correspondance globale' * 5.1 * 5 * 5.1 * 5.3 * FINISHED git commit -am 5.3git commit -am 5.3git commit -am 5.3 FUCK YEAH git commit -am 5.3git commit -am 5.3git commit -am 5.3! :DDD * corrected typos * changed modèle for schéma * corrected typo * corrected typo * corrected typo * corrected typo * corrected typo * corrected typo * corrected typo * corrected typo * corrected typo * corrected typo --- README-cn.md | 21 +-- README-es.md | 3 +- README-fr.md | 468 +++++++++++++++++++++++++++++++++++++++++++++++++++ README-ja.md | 3 +- README.md | 4 +- 5 files changed, 486 insertions(+), 13 deletions(-) create mode 100644 README-fr.md diff --git a/README-cn.md b/README-cn.md index 2fbcee53..57b0b34f 100644 --- a/README-cn.md +++ b/README-cn.md @@ -6,12 +6,13 @@ ## 翻译: * [English](README.md) -* [Spanish](README-es.md) +* [Español](README-es.md) +* [Français](README-fr.md) * [中文版](README-cn.md) * [日本語](README-ja.md) ## 什么是正则表达式? - + > 正则表达式是一组由字母和符号组成的特殊文本, 它可以用来从文本中找出满足你想要的格式的句子. @@ -69,7 +70,7 @@ 例如: 一个正则表达式 `the`, 它表示一个规则: 由字母`t`开始,接着是`h`,再接着是`e`. -"the" => The fat cat sat on the mat. +"the" => The fat cat sat on the mat.[在线练习](https://regex101.com/r/dmRygT/1) @@ -106,7 +107,7 @@ ## 2.1 点运算符 `.` -`.`是元字符中最简单的例子. +`.`是元字符中最简单的例子. `.`匹配任意单个字符, 但不匹配换行符. 例如, 表达式`.ar`匹配一个任意字符后面跟着是`a`和`r`的字符串. @@ -152,7 +153,7 @@ ## 2.3 重复次数 -后面跟着元字符 `+`, `*` or `?` 的, 用来指定匹配子模式的次数. +后面跟着元字符 `+`, `*` or `?` 的, 用来指定匹配子模式的次数. 这些元字符在不同的情况下有着不同的意思. ### 2.3.1 `*` 号 @@ -218,7 +219,7 @@ 我们可以省略第二个参数. 例如, `[0-9]{2,}` 匹配至少两位 0~9 的数字. -如果逗号也省略掉则表示重复固定的次数. +如果逗号也省略掉则表示重复固定的次数. 例如, `[0-9]{3}` 匹配3位数字@@ -353,7 +354,7 @@ `?=...` 前置约束(存在), 表示第一部分表达式必须跟在 `?=...`定义的表达式之后. 返回结果只瞒住第一部分表达式. -定义一个前置约束(存在)要使用 `()`. 在括号内部使用一个问号和等号: `(?=...)`. +定义一个前置约束(存在)要使用 `()`. 在括号内部使用一个问号和等号: `(?=...)`. 前置约束的内容写在括号中的等号后面. 例如, 表达式 `[T|t]he(?=\sfat)` 匹配 `The` 和 `the`, 在括号中我们又定义了前置约束(存在) `(?=\sfat)` ,即 `The` 和 `the` 后面紧跟着 `(空格)fat`. @@ -367,7 +368,7 @@ ### 4.2 `?!...` 前置约束-排除 前置约束-排除 `?!` 用于筛选所有匹配结果, 筛选条件为 其后不跟随着定义的格式 -`前置约束-排除` 定义和 `前置约束(存在)` 一样, 区别就是 `=` 替换成 `!` 也就是 `(?!...)`. +`前置约束-排除` 定义和 `前置约束(存在)` 一样, 区别就是 `=` 替换成 `!` 也就是 `(?!...)`. 表达式 `[T|t]he(?!\sfat)` 匹配 `The` 和 `the`, 且其后不跟着 `(空格)fat`. @@ -429,7 +430,7 @@ ### 5.2 全局搜索 (Global search) -修饰符 `g` 常用语执行一个全局搜索匹配, 即(不仅仅返回第一个匹配的, 而是返回全部). +修饰符 `g` 常用语执行一个全局搜索匹配, 即(不仅仅返回第一个匹配的, 而是返回全部). 例如, 表达式 `/.(at)/g` 表示搜索 任意字符(除了换行) + `at`, 并返回全部结果.+ +[Essayer l'expression régulière](https://regex101.com/r/8Efx5G/1) + +## 5. Drapeaux + +Les drapeaux sont aussi appelés modifieurs car ils modifient la sortie d'une expression régulière. Ces drapeaux peuvent être utilisés +dans n'importe quel ordre et combinaison et font partie intégrante de la RegExp. + +|Drapeau|Description| +|:----:|----| +|i|Insensible à la casse: Définit que la correspondance sera insensible à la casse.| +|g|Recherche globale: Recherche la correspondance dans la string entière.| +|m|Multiligne: Meta-caractère ancre qui agit sur toutes les lignes.| + +### 5.1 Insensible à la casse + +Le modifieur `i` est utilisé pour faire une correspondance insensible à la casse. Par exemple, l'expression régulière `/The/gi` signifie: la lettre +`T` majuscule, suivie par le caractère `h` minscule, suivi par le caractère `e` minuscule. Et à la fin de l'expression régulière, le drapeau `i` dit au +moteur d'expression régulière d'ignorer la casse. Comme vous pouvez le voir, nous mettons aussi un drapeau `g` parce que nous voulons chercher le schéma dans +la string entière. + +@@ -446,7 +447,7 @@ ### 5.3 多行修饰符 (Multiline) -多行修饰符 `m` 常用语执行一个多行匹配. +多行修饰符 `m` 常用语执行一个多行匹配. 像之前介绍的 `(^,$)` 用于检查格式是否是在待检测字符串的开头或结尾. 但我们如果想要它在每行的开头和结尾生效, 我们需要用到多行修饰符 `m`. diff --git a/README-es.md b/README-es.md index 64ca5965..6988406c 100644 --- a/README-es.md +++ b/README-es.md @@ -6,7 +6,8 @@ ## Translations: * [English](README.md) -* [Español](README-es.md) +* [Español](README-es.md) +* [Français](README-fr.md) * [中文版](README-cn.md) * [日本語](README-ja.md) diff --git a/README-fr.md b/README-fr.md new file mode 100644 index 00000000..931abd1b --- /dev/null +++ b/README-fr.md @@ -0,0 +1,468 @@ ++ +[Essayer l'expression régulière](https://regex101.com/r/IDDARt/1) + +### 4.2 Recherche en avant négative + +La recherche en avant négative est utilisée quand nous avons besoin de trouver une string qui n'est pas suivie d'un schéma. La recherche en avant négative +est définie de la même manière que la recherche en avant positive mais la seule différence est qu'à la place du signe égual `=` nous utilisons le caractère de négation `!` +i.e. `(?!...)`. Regardons l'expression régulière suivante `[T|t]he(?!\sfat)` qui signifie: trouve tous les mots `The` ou `the` de la string +qui ne sont pas suivis du mot `fat` précédé d'un espace. + +
++
+
+ +## Traductions: + +* [English](README.md) +* [Español](README-es.md) +* [Français](README-fr.md) +* [中文版](README-cn.md) +* [日本語](README-ja.md) + +## Qu'est-ce qu'une expression régulière? + +> Une expression régulière est un groupement de caractères ou symboles utilisés pour trouver un schéma spécifique dans un texte. + +Une expression régulière est un schéma qui est comparée à une chaîne de caractères de gauche à droite. Le mot "Expression régulière" +est un terme entier, souvent abrégé par "regex" ou "regexp". Une expression régulière est utilisée pour remplacer un texte à l'intérieur +d'une *string* (une chaîne de caractères), valider un formulaire, extraire une portion de string basée sur un schéma, et bien plus encore. + +Imaginons que nous écrivons une application et que nous voulons définir des règles pour le choix d'un pseudonyme. Nous voulons autoriser +le pseudonyme à contenir des lettres, des nombres, des underscores et des traits d'union. Nous voulons aussi limiter le nombre +de caractères dans le pseudonyme pour qu'il n'ait pas l'air moche. Nous utilisons l'expression régulière suivante pour valider un pseudonyme: +
++
+ +L'expression régulière ci-dessus peut accepter les strings `john_doe`, `jo-hn_doe` et `john12_as`. Ça ne fonctionne pas avec `Jo` car +cette string contient une lettre majuscule et elle est trop courte. + +## Table des matières + +- [Introduction](#1-introduction) +- [Meta-caractères](#2-meta-caractères) + - [Full stop](#21-full-stop) + - [Inclusion de caractères](#22-inclusion-de-caractères) + - [Exclusion de caractères](#221-exclusion-de-caractères) + - [Répétitions](#23-répétitions) + - [Astérisque](#231-Asterisque) + - [Le Plus](#232-le-plus) + - [Le Point d'Interrogation](#233-le-point-d'interrogation) + - [Accolades](#24-accolades) + - [Groupement de caractères](#25-groupement-de-caractères) + - [Alternation](#26-alternation) + - [Caractère d'échappement](#27-caractère-d'échappement) + - [Ancres](#28-ancres) + - [Circonflexe](#281-circonflexe) + - [Dollar](#282-dollar) +- [Liste de caractères abrégés](#3-liste-de-caractères-abrégés) +- [Recherche](#4-recherche) + - [Recherche avant positive](#41-recherche-avant-positive) + - [Recherche avant négative](#42-recherche-avant-négative) + - [Recherche arrière positive](#43-recherche-arrière-positive) + - [Recherche arrière négative](#44-recherche-arrière-négative) +- [Drapeaux](#5-drapeaux) + - [Insensible à la casse](#51-insensible-à-la-casse) + - [Correspondance globale](#52-recherche-globale) + - [Multilignes](#53-multilignes) + +## 1. Introduction + +Une expression régulière est un schéma de caractères utilisés pour effectuer une recherche dans un text. +Par exemple, l'expression régulière `the` signifie: la lettre `t`, suivie de la lettre `h`, suivie de la lettre `e`. + ++
+"the" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/dmRygT/1) + +L'expression régulière `123` coïncide à la chaîne `123`. Chaque caractère de l'expression régulière est comparée à la chaine passée en entrée, caractère par caractère. Les expressions régulières sont normalement sensibles à la casse, donc l'expression régulière `The` ne va pas coïncider à la chaine de caractère `the`. + ++"The" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/1paXsy/1) + +## 2. Meta-caractères + +Les meta-caractères sont les bloques de construction des expressions régulières. Les meta-caractères sont interprétés de manière particulière. Certains meta-caractères ont des significations spéciales et sont écrits entre crochets. +Significations des meta-caractères: + +|Meta-caractère|Description| +|:----:|----| +|.|Un point coïncide avec n'importe quel caractère unique à part le retour à la ligne.| +|[ ]|Classe de caractères. Coïncide avec n'importe quels caractères entre crochets.| +|[^ ]|Négation de classe de caractère. Coïncide avec n'importe quels caractères qui n'est pas entre les crochets.| +|*|Coïncide avec 0 ou plus répétitions du caractère précédent.| +|+|Coïncide avec 1 ou plus répétitions du caractère précédent.| +|?|Rend le caractère précédent optionnel.| +|{n,m}|Accolades. Coïncide avec au moins "n" mais pas plus que "m" répétition(s) du caractère précédent.| +|(xyz)|Groupe de caractères. Coïncide avec les caractères "xyz" dans l'ordre exact.| +|||Alternation (ou). Coïncide soit avec le caractère avant ou après le symbol.| +|\|Échappe le prochain caractère. Cela permet de faire coïncider des caractères réservés tels que[ ] ( ) { } . * + ? ^ $ \ || +|^|Coïncide avec le début de la chaîne de caractères.| +|$|Coïncide avec la fin de la chaîne de caractères.| + +## 2.1 Full stop + +Le full stop `.` est l'exemple le plus simple d'un meta-caratère. Le `.` coïncide avec n'importe quel caractère unique, mais ne coïncide pas avec les caractères de retour ou de nouvelle ligne. Par exemple, l'expression régulière `.ar` signifie: n'importe quel caractère suivi par la lettre `a`, suivie par la lettre `r`. + ++".ar" => The car parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/xc9GkU/1) + +## 2.2 Inclusions de caractères + +Les inclusions de caractères sont également appelées classes de caractères. Les crochets sont utilisés pour spécifier les inclusions de caractères. Un trait d'union utilisé dans une inclusion de caractères permet de définir une gamme de caractères. L'ordre utilisé dans la gamme de caractère n'a pas d'importance. Par exemple, l'expression régulière `[Tt]he` signifie: un `T` majuscule ou `t` minucule, suivi par la lettre `h`, suivie par la lettre `e`. + ++"[Tt]he" => The car parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/2ITLQ4/1) + +L'utilisation du point dans une inclusion de caractère signifie toutefois un `.` littéral. L'expression régulière `ar[.]` signifie: un `a` minuscule, suivi par la lettre `r` minuscule, suvie par un `.` (point). + ++"ar[.]" => A garage is a good place to park a car. ++ +[Essayer l'expression régulière](https://regex101.com/r/wL3xtE/1) + +### 2.2.1 Exclusion de caractères + +En règle générale, le caractère circonflexe représente le début d'une chaîne de caractères. Néanmoins, lorsqu'il est utilisé après le crochet ouvrant, il permet d'exclure la gamme de caractère(s). Par exemple, l'expression régulière `[^c]ar` signifie: n'importe quel caractère sauf `c`, suivi par la lettre `a`, suivie par la lettre `r`. + ++"[^c]ar" => The car parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/nNNlq3/1) + +## 2.3 Répétitions + +Les meta-caractères suivants `+`, `*` ou `?` sont utilisés pour spécifier combien de fois un sous-schéma peut apparaître. Ces meta-caractères agissent +différemment selon la situation dans laquelle ils sont utilisés. + +### 2.3.1 Astérisque + +Le symbole `*` correspond à zéro ou plus de répétitions du schéma précédent. L'expression régulière `a*` signifie: zéro ou plus de répétitions +du précédent `a` minuscule. Mais si il se trouve après une liste de caractères alors il s'agit de la répétition de la liste entière. +Par exemple, l'expression régulière `[a-z]*` signifie: n'importe combien de lettres minuscules. + ++"[a-z]*" => The car parked in the garage #21. ++ +[Essayer l'expression régulière](https://regex101.com/r/7m8me5/1) + +Le symbole `*` peut être utilisé avec le meta-caractère `.` pour correspondre à n'importe quelle chaîne de caractères `.*`. Le symbole `*` peut être utilisé avec le +caractère espace vide `\s` pour correspondre à une chaîne d'espaces vides. Par exemple, l'expression `\s*cat\s*` signifie: zéro ou plus +d'espaces, suivis du caractère `c` minuscule, suivi par le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par +zéro ou plus d'espaces. + ++"\s*cat\s*" => The fat cat sat on the concatenation. ++ +[Essayer l'expression régulière](https://regex101.com/r/gGrwuz/1) + +### 2.3.2 Le Plus + +Le meta-caractère `+` correspond à une ou plusieurs répétitions du caractère précédent. Par exemple, l'expression régulière `c.+t` signifie: la lettre `c` minuscule, suivie par au moins un caractère, suivi par la lettre `t` minuscule. Le `t` coïncide par conséquent avec le dernier `t` de la phrase. + ++"c.+t" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/Dzf9Aa/1) + +### 2.3.3 Le point d'interrogation + +Le meta-caractère `?` rend le caractère précédent optionel. Ce symbole permet de faire coïncider 0 ou une instance du caractère précédent. Par exemple, l'expression régulière `[T]?he` signifie: la lettre `T` majuscule optionelle, suivie par la lettre `h` minuscule, suivie par la lettre `e` minuscule. + ++"[T]he" => The car is parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/cIg9zm/1) + ++"[T]?he" => The car is parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/kPpO2x/1) + +## 2.4 Accolades + +Dans une expression régulière, les accolades, qui sont aussi appelée quantifieurs, sont utilisées pour spécifier le nombre de fois qu'un +caractère ou un groupe de caractères peut être répété. Par exemple, l'expression régulière `[0-9]{2,3}` signifie: Trouve au moins 2 chiffres mais pas plus de 3 +(caractères dans la gamme de 0 à 9). + ++"[0-9]{2,3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[Essayer l'expression régulière](https://regex101.com/r/juM86s/1) + +Nous pouvons omettre le second nombre. Par exemple, l'expression régulière `[0-9]{2,}` signifie: Trouve 2 chiffres ou plus. Si nous supprimons aussi +la virgule l'expression régulière `[0-9]{3}` signifie: Trouve exactement 3 chiffres. + ++"[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[Essayer l'expression régulière](https://regex101.com/r/Gdy4w5/1) + ++"[0-9]{3}" => The number was 9.9997 but we rounded it off to 10.0. ++ +[Essayer l'expression régulière](https://regex101.com/r/Sivu30/1) + +## 2.5 Groupement de caractères + +Un groupement de caractères est un groupe de sous-schémas qui sont écris dans des parenthèses `(...)`. Nous avions mentionné plus tôt que, dans une expression régulière, +si nous mettons un quantifieur après un caractère alors le caractère précédent sera répété. Mais si nous mettons un quantifieur après un groupement de caractères alors +il répète le groupement de caractères entier. Par exemple, l'expression régulière `(ab)*` trouve zéro ou plus de répétitions des caractères "ab". +Nous pouvons aussi utiliser le meta-caractère d'alternation `|` à l'intérieur d'un groupement. Par exemple, l'expression régulière `(c|g|p)ar` signifie: caractère `c` minuscule, +`g` ou `p`, suivi par le caractère `a`, suivi par le caractère `r`. + ++"(c|g|p)ar" => The car is parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/tUxrBG/1) + +## 2.6 Alternation + +Dans une expression régulière, la barre verticale `|` est utilisée pour définir une alternation. L'alternation est comme une condition entre plusieurs expressions. Maintenant, +nous pourrions penser que la liste de caractères et l'alternation sont la même chose. Mais la grande différence entre une liste de caractères et l'alternation +est que la liste de caractères fonctionne au niveau des caractères mais l'alternation fonctionne au niveau de l'expression. Par exemple, l'expression régulière +`(T|t)he|car` signifie: le caractère `T` majuscule ou `t` minuscule, suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule +ou le caractère `c` minuscule, suivi par le caractère `a` minuscule, suivit par le caractère `r` minuscule. + ++"(T|t)he|car" => The car is parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/fBXyX0/1) + +## 2.7 Caractère d'échappement + +L'antislash `\` est utilisé dans les expressions régulières pour échapper (ignorer) le caractère suivant. Cela permet de spécifier un symbole comme caractère à trouver +y compris les caractères réservés `{ } [ ] / \ + * . $ ^ | ?`. Pour utiliser un caractère spécial comme caractère à trouver, préfixer `\` avant celui-ci. +Par exemple, l'expression régulière `.` est utilisée pour trouver n'importe quel caractère sauf le retour de ligne. Donc pour trouver `.` dans une string +l'expression régulière `(f|c|m)at\.?` signifie: la lettre minuscule `f`, `c` ou `m`, suivie par le caractère `a` minuscule, suivi par la lettre +`t` minuscule, suivie par le caractère optionnel `.`. + ++"(f|c|m)at\.?" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/DOc5Nu/1) + +## 2.8 Ancres + +Dans les expressions régulières, nous utilisons des ancres pour vérifier si le symbole trouvé est le premier ou dernier symbole de la +string. Il y a 2 types d'ancres: Le premier type est le circonflexe `^` qui cherche si le caractère est le premier +caractère de la string et le deuxième type est le Dollar `$` qui vérifie si le caractère est le dernier caractère de la string. + +### 2.8.1 Circonflexe + +Le symbole circonflexe `^` est utilisé pour vérifier si un caractère est le premier caractère de la string. Si nous appliquons l'expression régulière +suivante `^a` (si a est le premier symbole) à la string `abc`, ça coïncide. Mais si nous appliquons l'expression régulière `^b` sur cette même string, +ça ne coïncide pas. Parce que dans la string `abc` "b" n'est pas le premier symbole. Regardons une autre expression régulière +`^(T|t)he` qui signifie: le caractère `T` majuscule ou le caractère `t` minuscule est le premier symbole de la string, +suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule. + ++"(T|t)he" => The car is parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/5ljjgB/1) + ++"^(T|t)he" => The car is parked in the garage. ++ +[Essayer l'expression régulière](https://regex101.com/r/jXrKne/1) + +### 2.8.2 Dollar + +Le symbole Dollar `$` est utilisé pour vérifier si un caractère est le dernier caractère d'une string. Par exemple, l'expression régulière +`(at\.)$` signifie: un caractère `a` minuscule, suivi par un caractère `t` minuscule, suivi par un caractère `.` et tout cela doit être +à la fin de la string. + ++"(at\.)" => The fat cat. sat. on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/y4Au4D/1) + ++"(at\.)$" => The fat cat. sat. on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/t0AkOd/1) + +## 3. Liste de caractères abrégés + +Les expressions régulières fournissent des abréviations pour les listes de caractères, ce qui offres des raccourcis pratiques pour +les expressions régulières souvent utilisées. Ces abréviations sont les suivantes: + +|Abréviation|Description| +|:----:|----| +|.|N'importe quel caractère à part le retour de ligne| +|\w|Caractères alphanumériques: `[a-zA-Z0-9_]`| +|\W|Caractères non-alphanumériques: `[^\w]`| +|\d|Chiffres: `[0-9]`| +|\D|Non-numériques: `[^\d]`| +|\s|Espace vide: `[\t\n\f\r\p{Z}]`| +|\S|Tout sauf espace vide: `[^\s]`| + +## 4. Recherche + +La recherche en avant et en arrière sont un type spécifique appelé ***groupe non-capturant*** (utilisés pour trouver un schéma mais pas +pour l'inclure dans la liste de correspondance). Les recherches positives sont utilisées quand nous avons la condition qu'un schéma doit être précédé ou suivi +par un autre schéma. Par exemple, nous voulons tous les chiffres qui sont précédés par le caractère `$` dans la string suivante `$4.44 and $10.88`. +Nous allons utiliser l'expression régulière suivante `(?<=\$)[0-9\.]*` qui signifie: Trouver tous les nombres qui contiennent le caractère `.` et sont précédés +par le caractère `$`. Les recherches que nous trouvons dans les expressions régulières sont les suivantes: + +|Symbole|Description| +|:----:|----| +|?=|Recherche en avant positive| +|?!|Recherche en avant négative| +|?<=|Recherche en arrière positive| +|? +"[T|t]he(?=\sfat)" => The fat cat sat on the mat. ++"[T|t]he(?!\sfat)" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/V32Npg/1) + +### 4.3 Recherche en arrière positive + +La recherche en arrière positive est utilisée pour trouver une string précédée d'un schéma. La recherche en arrière positive se note +`(?<=...)`. Par exemple, l'expression régulière `(?<=[T|t]he\s)(fat|mat)` signifie: trouve tous les mots `fat` ou `mat` de la string qui +se trouve après le mot `The` ou `the`. + ++"(?<=[T|t]he\s)(fat|mat)" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/avH165/1) + +### 4.4 Recherche en arrière négative + +La recherche en arrière négative est utilisée pour trouver une string qui n'est pas précédée d'un schéma. La recherche en arrière négative se note +`(? +"(?<![T|t]he\s)(cat)" => The cat sat on cat. ++"The" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/dpQyf9/1) + ++"/The/gi" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/ahfiuh/1) + +### 5.2 Correspondance globale + +Le modifieur `g` est utilisé pour faire une recherche globale (trouver toutes les strings plutôt que de s'arrêter à la première correspondance ). Par exemple, +l'expression régulière `/.(at)/g` signifie: n'importe quel caractère sauf le retour de ligne, suivi par le caractère `a` minuscule, suivi par le caractère +`t` minuscule. Grâce au drapeau `g` à la fin de l'expression régulière maintenant il trouvera toutes les correspondances de toute la string. + ++"/.(at)/" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/jnk6gM/1) + ++"/.(at)/g" => The fat cat sat on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/dO1nef/1) + +### 5.3 Multilignes + +Le modifieur `m` est utilisé pour trouver une correspondance multiligne. Comme mentionné plus tôt, les ancres `(^, $)` sont utilisés pour vérifier si le schéma +se trouve au début ou à la fin de la string. Mais si nous voulons que l'ancre soit sur chaque ligne nous utilisons le drapeau `m`. Par exemple, l'expression régulière +`/at(.)?$/gm` signifie: le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par optionnellement n'importe quel caractère à part le retour de ligne. +Grâce au drapeau `m` maintenant le moteur d'expression régulière trouve le schéma à chaque début de ligne dans la string. + ++"/.at(.)?$/" => The fat + cat sat + on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/hoGMkP/1) + ++"/.at(.)?$/gm" => The fat + cat sat + on the mat. ++ +[Essayer l'expression régulière](https://regex101.com/r/E88WE2/1) + +## Contribution + +* Signaler les problèmes (issues) +* Ouvrir des "pull requests" pour les améliorations +* Parlez-en autour de vous ! +* Contactez moi en anglais à ziishaned@gmail.com ou [](https://twitter.com/ziishaned) + +## License + +MIT © [Zeeshan Ahmed](mailto:ziishaned@gmail.com) diff --git a/README-ja.md b/README-ja.md index 523928ea..bdce2acc 100644 --- a/README-ja.md +++ b/README-ja.md @@ -6,7 +6,8 @@ ## 翻訳 * [English](README.md) -* [Español](README-es.md) +* [Español](README-es.md) +* [Français](README-fr.md) * [中文版](README-cn.md) * [日本語](README-ja.md) diff --git a/README.md b/README.md index ece50f70..7a05ff3b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ ## Translations: * [English](README.md) -* [Español](README-es.md) +* [Español](README-es.md) +* [Français](README-fr.md) * [中文版](README-cn.md) * [日本語](README-ja.md) @@ -260,6 +261,7 @@ or lowercase character `c`, followed by lowercase character `a`, followed by low Backslash `\` is used in regular expression to escape the next character. This allows us to specify a symbol as a matching character including reserved characters `{ } [ ] / \ + * . $ ^ | ?`. To use a special character as a matching character prepend `\` before it. + For example, the regular expression `.` is used to match any character except newline. Now to match `.` in an input string the regular expression `(f|c|m)at\.?` means: lowercase letter `f`, `c` or `m`, followed by lowercase character `a`, followed by lowercase letter `t`, followed by optional `.` character. From 4b641cd11de81057d9f5213766839d296b5c0a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Borbo=C3=ABn?=Date: Sat, 19 Aug 2017 01:59:19 +0200 Subject: [PATCH 033/212] RegExp image in french, typo corrected (#67) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Some typo corrected * Typographics rules (as space before :) * égual - égal --- README-fr.md | 86 ++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/README-fr.md b/README-fr.md index 931abd1b..729e2dda 100644 --- a/README-fr.md +++ b/README-fr.md @@ -24,7 +24,7 @@ le pseudonyme à contenir des lettres, des nombres, des underscores et des trait de caractères dans le pseudonyme pour qu'il n'ait pas l'air moche. Nous utilisons l'expression régulière suivante pour valider un pseudonyme:
-
L'expression régulière ci-dessus peut accepter les strings `john_doe`, `jo-hn_doe` et `john12_as`. Ça ne fonctionne pas avec `Jo` car @@ -62,7 +62,7 @@ cette string contient une lettre majuscule et elle est trop courte. ## 1. Introduction Une expression régulière est un schéma de caractères utilisés pour effectuer une recherche dans un text. -Par exemple, l'expression régulière `the` signifie: la lettre `t`, suivie de la lettre `h`, suivie de la lettre `e`. +Par exemple, l'expression régulière `the` signifie : la lettre `t`, suivie de la lettre `h`, suivie de la lettre `e`.+
"the" => The fat cat sat on the mat. @@ -70,7 +70,7 @@ Par exemple, l'expression régulière `the` signifie: la lettre `t`, suivie de l [Essayer l'expression régulière](https://regex101.com/r/dmRygT/1) -L'expression régulière `123` coïncide à la chaîne `123`. Chaque caractère de l'expression régulière est comparée à la chaine passée en entrée, caractère par caractère. Les expressions régulières sont normalement sensibles à la casse, donc l'expression régulière `The` ne va pas coïncider à la chaine de caractère `the`. +L'expression régulière `123` coïncide à la chaîne `123`. Chaque caractère de l'expression régulière est comparée à la chaîne passée en entrée, caractère par caractère. Les expressions régulières sont normalement sensibles à la casse, donc l'expression régulière `The` ne va pas coïncider à la chaîne de caractère `the`."The" => The fat cat sat on the mat. @@ -100,7 +100,7 @@ Significations des meta-caractères: ## 2.1 Full stop -Le full stop `.` est l'exemple le plus simple d'un meta-caratère. Le `.` coïncide avec n'importe quel caractère unique, mais ne coïncide pas avec les caractères de retour ou de nouvelle ligne. Par exemple, l'expression régulière `.ar` signifie: n'importe quel caractère suivi par la lettre `a`, suivie par la lettre `r`. +Le full stop `.` est l'exemple le plus simple d'un meta-caratère. Le `.` coïncide avec n'importe quel caractère unique, mais ne coïncide pas avec les caractères de retour ou de nouvelle ligne. Par exemple, l'expression régulière `.ar` signifie : n'importe quel caractère suivi par la lettre `a`, suivie par la lettre `r`.".ar" => The car parked in the garage. @@ -110,7 +110,7 @@ Le full stop `.` est l'exemple le plus simple d'un meta-caratère. Le `.` coïnc ## 2.2 Inclusions de caractères -Les inclusions de caractères sont également appelées classes de caractères. Les crochets sont utilisés pour spécifier les inclusions de caractères. Un trait d'union utilisé dans une inclusion de caractères permet de définir une gamme de caractères. L'ordre utilisé dans la gamme de caractère n'a pas d'importance. Par exemple, l'expression régulière `[Tt]he` signifie: un `T` majuscule ou `t` minucule, suivi par la lettre `h`, suivie par la lettre `e`. +Les inclusions de caractères sont également appelées classes de caractères. Les crochets sont utilisés pour spécifier les inclusions de caractères. Un trait d'union utilisé dans une inclusion de caractères permet de définir une gamme de caractères. L'ordre utilisé dans la gamme de caractère n'a pas d'importance. Par exemple, l'expression régulière `[Tt]he` signifie : un `T` majuscule ou `t` minuscule, suivi par la lettre `h`, suivie par la lettre `e`."[Tt]he" => The car parked in the garage. @@ -118,7 +118,7 @@ Les inclusions de caractères sont également appelées classes de caractères. [Essayer l'expression régulière](https://regex101.com/r/2ITLQ4/1) -L'utilisation du point dans une inclusion de caractère signifie toutefois un `.` littéral. L'expression régulière `ar[.]` signifie: un `a` minuscule, suivi par la lettre `r` minuscule, suvie par un `.` (point). +L'utilisation du point dans une inclusion de caractère signifie toutefois un `.` littéral. L'expression régulière `ar[.]` signifie : un `a` minuscule, suivi par la lettre `r` minuscule, suivie par un `.` (point)."ar[.]" => A garage is a good place to park a car. @@ -128,7 +128,7 @@ L'utilisation du point dans une inclusion de caractère signifie toutefois un `. ### 2.2.1 Exclusion de caractères -En règle générale, le caractère circonflexe représente le début d'une chaîne de caractères. Néanmoins, lorsqu'il est utilisé après le crochet ouvrant, il permet d'exclure la gamme de caractère(s). Par exemple, l'expression régulière `[^c]ar` signifie: n'importe quel caractère sauf `c`, suivi par la lettre `a`, suivie par la lettre `r`. +En règle générale, le caractère circonflexe représente le début d'une chaîne de caractères. Néanmoins, lorsqu'il est utilisé après le crochet ouvrant, il permet d'exclure la gamme de caractère(s). Par exemple, l'expression régulière `[^c]ar` signifie : n'importe quel caractère sauf `c`, suivi par la lettre `a`, suivie par la lettre `r`."[^c]ar" => The car parked in the garage. @@ -143,9 +143,9 @@ différemment selon la situation dans laquelle ils sont utilisés. ### 2.3.1 Astérisque -Le symbole `*` correspond à zéro ou plus de répétitions du schéma précédent. L'expression régulière `a*` signifie: zéro ou plus de répétitions +Le symbole `*` correspond à zéro ou plus de répétitions du schéma précédent. L'expression régulière `a*` signifie : zéro ou plus de répétitions du précédent `a` minuscule. Mais si il se trouve après une liste de caractères alors il s'agit de la répétition de la liste entière. -Par exemple, l'expression régulière `[a-z]*` signifie: n'importe combien de lettres minuscules. +Par exemple, l'expression régulière `[a-z]*` signifie : n'importe combien de lettres minuscules."[a-z]*" => The car parked in the garage #21. @@ -154,7 +154,7 @@ Par exemple, l'expression régulière `[a-z]*` signifie: n'importe combien de le [Essayer l'expression régulière](https://regex101.com/r/7m8me5/1) Le symbole `*` peut être utilisé avec le meta-caractère `.` pour correspondre à n'importe quelle chaîne de caractères `.*`. Le symbole `*` peut être utilisé avec le -caractère espace vide `\s` pour correspondre à une chaîne d'espaces vides. Par exemple, l'expression `\s*cat\s*` signifie: zéro ou plus +caractère espace vide `\s` pour correspondre à une chaîne d'espaces vides. Par exemple, l'expression `\s*cat\s*` signifie : zéro ou plus d'espaces, suivis du caractère `c` minuscule, suivi par le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par zéro ou plus d'espaces. @@ -166,7 +166,7 @@ zéro ou plus d'espaces. ### 2.3.2 Le Plus -Le meta-caractère `+` correspond à une ou plusieurs répétitions du caractère précédent. Par exemple, l'expression régulière `c.+t` signifie: la lettre `c` minuscule, suivie par au moins un caractère, suivi par la lettre `t` minuscule. Le `t` coïncide par conséquent avec le dernier `t` de la phrase. +Le meta-caractère `+` correspond à une ou plusieurs répétitions du caractère précédent. Par exemple, l'expression régulière `c.+t` signifie : la lettre `c` minuscule, suivie par au moins un caractère, suivi par la lettre `t` minuscule. Le `t` coïncide par conséquent avec le dernier `t` de la phrase."c.+t" => The fat cat sat on the mat. @@ -176,7 +176,7 @@ Le meta-caractère `+` correspond à une ou plusieurs répétitions du caractèr ### 2.3.3 Le point d'interrogation -Le meta-caractère `?` rend le caractère précédent optionel. Ce symbole permet de faire coïncider 0 ou une instance du caractère précédent. Par exemple, l'expression régulière `[T]?he` signifie: la lettre `T` majuscule optionelle, suivie par la lettre `h` minuscule, suivie par la lettre `e` minuscule. +Le meta-caractère `?` rend le caractère précédent optionnel. Ce symbole permet de faire coïncider 0 ou une instance du caractère précédent. Par exemple, l'expression régulière `[T]?he` signifie : la lettre `T` majuscule optionnelle, suivie par la lettre `h` minuscule, suivie par la lettre `e` minuscule."[T]he" => The car is parked in the garage. @@ -193,7 +193,7 @@ Le meta-caractère `?` rend le caractère précédent optionel. Ce symbole perme ## 2.4 Accolades Dans une expression régulière, les accolades, qui sont aussi appelée quantifieurs, sont utilisées pour spécifier le nombre de fois qu'un -caractère ou un groupe de caractères peut être répété. Par exemple, l'expression régulière `[0-9]{2,3}` signifie: Trouve au moins 2 chiffres mais pas plus de 3 +caractère ou un groupe de caractères peut être répété. Par exemple, l'expression régulière `[0-9]{2,3}` signifie : trouve au moins 2 chiffres mais pas plus de 3 (caractères dans la gamme de 0 à 9).@@ -202,8 +202,8 @@ caractère ou un groupe de caractères peut être répété. Par exemple, l'expr [Essayer l'expression régulière](https://regex101.com/r/juM86s/1) -Nous pouvons omettre le second nombre. Par exemple, l'expression régulière `[0-9]{2,}` signifie: Trouve 2 chiffres ou plus. Si nous supprimons aussi -la virgule l'expression régulière `[0-9]{3}` signifie: Trouve exactement 3 chiffres. +Nous pouvons omettre le second nombre. Par exemple, l'expression régulière `[0-9]{2,}` signifie : trouve 2 chiffres ou plus. Si nous supprimons aussi +la virgule l'expression régulière `[0-9]{3}` signifie : trouve exactement 3 chiffres."[0-9]{2,}" => The number was 9.9997 but we rounded it off to 10.0. @@ -219,10 +219,10 @@ la virgule l'expression régulière `[0-9]{3}` signifie: Trouve exactement 3 chi ## 2.5 Groupement de caractères -Un groupement de caractères est un groupe de sous-schémas qui sont écris dans des parenthèses `(...)`. Nous avions mentionné plus tôt que, dans une expression régulière, +Un groupement de caractères est un groupe de sous-schémas qui sont écrits dans des parenthèses `(...)`. Nous avions mentionné plus tôt que, dans une expression régulière, si nous mettons un quantifieur après un caractère alors le caractère précédent sera répété. Mais si nous mettons un quantifieur après un groupement de caractères alors il répète le groupement de caractères entier. Par exemple, l'expression régulière `(ab)*` trouve zéro ou plus de répétitions des caractères "ab". -Nous pouvons aussi utiliser le meta-caractère d'alternation `|` à l'intérieur d'un groupement. Par exemple, l'expression régulière `(c|g|p)ar` signifie: caractère `c` minuscule, +Nous pouvons aussi utiliser le meta-caractère d'alternation `|` à l'intérieur d'un groupement. Par exemple, l'expression régulière `(c|g|p)ar` signifie : caractère `c` minuscule, `g` ou `p`, suivi par le caractère `a`, suivi par le caractère `r`.@@ -236,7 +236,7 @@ Nous pouvons aussi utiliser le meta-caractère d'alternation `|` à l'intérieur Dans une expression régulière, la barre verticale `|` est utilisée pour définir une alternation. L'alternation est comme une condition entre plusieurs expressions. Maintenant, nous pourrions penser que la liste de caractères et l'alternation sont la même chose. Mais la grande différence entre une liste de caractères et l'alternation est que la liste de caractères fonctionne au niveau des caractères mais l'alternation fonctionne au niveau de l'expression. Par exemple, l'expression régulière -`(T|t)he|car` signifie: le caractère `T` majuscule ou `t` minuscule, suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule +`(T|t)he|car` signifie : le caractère `T` majuscule ou `t` minuscule, suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule ou le caractère `c` minuscule, suivi par le caractère `a` minuscule, suivit par le caractère `r` minuscule.@@ -250,7 +250,7 @@ ou le caractère `c` minuscule, suivi par le caractère `a` minuscule, suivit pa L'antislash `\` est utilisé dans les expressions régulières pour échapper (ignorer) le caractère suivant. Cela permet de spécifier un symbole comme caractère à trouver y compris les caractères réservés `{ } [ ] / \ + * . $ ^ | ?`. Pour utiliser un caractère spécial comme caractère à trouver, préfixer `\` avant celui-ci. Par exemple, l'expression régulière `.` est utilisée pour trouver n'importe quel caractère sauf le retour de ligne. Donc pour trouver `.` dans une string -l'expression régulière `(f|c|m)at\.?` signifie: la lettre minuscule `f`, `c` ou `m`, suivie par le caractère `a` minuscule, suivi par la lettre +l'expression régulière `(f|c|m)at\.?` signifie : la lettre minuscule `f`, `c` ou `m`, suivie par le caractère `a` minuscule, suivi par la lettre `t` minuscule, suivie par le caractère optionnel `.`.@@ -262,7 +262,7 @@ l'expression régulière `(f|c|m)at\.?` signifie: la lettre minuscule `f`, `c` o ## 2.8 Ancres Dans les expressions régulières, nous utilisons des ancres pour vérifier si le symbole trouvé est le premier ou dernier symbole de la -string. Il y a 2 types d'ancres: Le premier type est le circonflexe `^` qui cherche si le caractère est le premier +string. Il y a 2 types d'ancres : Le premier type est le circonflexe `^` qui cherche si le caractère est le premier caractère de la string et le deuxième type est le Dollar `$` qui vérifie si le caractère est le dernier caractère de la string. ### 2.8.1 Circonflexe @@ -270,7 +270,7 @@ caractère de la string et le deuxième type est le Dollar `$` qui vérifie si l Le symbole circonflexe `^` est utilisé pour vérifier si un caractère est le premier caractère de la string. Si nous appliquons l'expression régulière suivante `^a` (si a est le premier symbole) à la string `abc`, ça coïncide. Mais si nous appliquons l'expression régulière `^b` sur cette même string, ça ne coïncide pas. Parce que dans la string `abc` "b" n'est pas le premier symbole. Regardons une autre expression régulière -`^(T|t)he` qui signifie: le caractère `T` majuscule ou le caractère `t` minuscule est le premier symbole de la string, +`^(T|t)he` qui signifie : le caractère `T` majuscule ou le caractère `t` minuscule est le premier symbole de la string, suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule.@@ -288,7 +288,7 @@ suivi par le caractère `h` minuscule, suivi par le caractère `e` minuscule. ### 2.8.2 Dollar Le symbole Dollar `$` est utilisé pour vérifier si un caractère est le dernier caractère d'une string. Par exemple, l'expression régulière -`(at\.)$` signifie: un caractère `a` minuscule, suivi par un caractère `t` minuscule, suivi par un caractère `.` et tout cela doit être +`(at\.)$` signifie : un caractère `a` minuscule, suivi par un caractère `t` minuscule, suivi par un caractère `.` et tout cela doit être à la fin de la string.@@ -306,24 +306,24 @@ Le symbole Dollar `$` est utilisé pour vérifier si un caractère est le dernie ## 3. Liste de caractères abrégés Les expressions régulières fournissent des abréviations pour les listes de caractères, ce qui offres des raccourcis pratiques pour -les expressions régulières souvent utilisées. Ces abréviations sont les suivantes: +les expressions régulières souvent utilisées. Ces abréviations sont les suivantes : |Abréviation|Description| |:----:|----| |.|N'importe quel caractère à part le retour de ligne| -|\w|Caractères alphanumériques: `[a-zA-Z0-9_]`| -|\W|Caractères non-alphanumériques: `[^\w]`| -|\d|Chiffres: `[0-9]`| -|\D|Non-numériques: `[^\d]`| -|\s|Espace vide: `[\t\n\f\r\p{Z}]`| -|\S|Tout sauf espace vide: `[^\s]`| +|\w|Caractères alphanumériques : `[a-zA-Z0-9_]`| +|\W|Caractères non-alphanumériques : `[^\w]`| +|\d|Chiffres : `[0-9]`| +|\D|Non-numériques : `[^\d]`| +|\s|Espace vide : `[\t\n\f\r\p{Z}]`| +|\S|Tout sauf espace vide : `[^\s]`| ## 4. Recherche La recherche en avant et en arrière sont un type spécifique appelé ***groupe non-capturant*** (utilisés pour trouver un schéma mais pas pour l'inclure dans la liste de correspondance). Les recherches positives sont utilisées quand nous avons la condition qu'un schéma doit être précédé ou suivi par un autre schéma. Par exemple, nous voulons tous les chiffres qui sont précédés par le caractère `$` dans la string suivante `$4.44 and $10.88`. -Nous allons utiliser l'expression régulière suivante `(?<=\$)[0-9\.]*` qui signifie: Trouver tous les nombres qui contiennent le caractère `.` et sont précédés +Nous allons utiliser l'expression régulière suivante `(?<=\$)[0-9\.]*` qui signifie : trouver tous les nombres qui contiennent le caractère `.` et sont précédés par le caractère `$`. Les recherches que nous trouvons dans les expressions régulières sont les suivantes: |Symbole|Description| @@ -337,8 +337,8 @@ par le caractère `$`. Les recherches que nous trouvons dans les expressions ré La recherche en avant assure que la première partie de l'expression soit suivie par l'expression recherchée. La valeur retournée contient uniquement le texte qui correspond à la première partie de l'expression. Pour définir une recherche en avant positive, on utilise -des parenthèses. Entre ces parenthèses, un point d'interrogation avec un signe égual est utilisé comme ça: `(?=...)`. L'expression de recherche -est écrite après le signe égual dans les parenthèses. Par exemple, l'expression régulière `[T|t]he(?=\sfat)` signifie: trouve optionnellement +des parenthèses. Entre ces parenthèses, un point d'interrogation avec un signe égal est utilisé comme cela : `(?=...)`. L'expression de recherche +est écrite après le signe égal dans les parenthèses. Par exemple, l'expression régulière `[T|t]he(?=\sfat)` signifie : trouve optionnellement la lettre `t` minuscule ou la lettre `T` majuscule, suivie par la lettre `h` minuscule, suivie par la lettre `e`. Entre parenthèses nous définissons la recherche en avant positive qui dit quelle est l'expression à chercher. `The` ou `the` qui sont suivies par le mot `fat` précédé d'un espace. @@ -351,8 +351,8 @@ la recherche en avant positive qui dit quelle est l'expression à chercher. `The ### 4.2 Recherche en avant négative La recherche en avant négative est utilisée quand nous avons besoin de trouver une string qui n'est pas suivie d'un schéma. La recherche en avant négative -est définie de la même manière que la recherche en avant positive mais la seule différence est qu'à la place du signe égual `=` nous utilisons le caractère de négation `!` -i.e. `(?!...)`. Regardons l'expression régulière suivante `[T|t]he(?!\sfat)` qui signifie: trouve tous les mots `The` ou `the` de la string +est définie de la même manière que la recherche en avant positive mais la seule différence est qu'à la place du signe égal `=` nous utilisons le caractère de négation `!` +i.e. `(?!...)`. Regardons l'expression régulière suivante `[T|t]he(?!\sfat)` qui signifie : trouve tous les mots `The` ou `the` de la string qui ne sont pas suivis du mot `fat` précédé d'un espace.@@ -364,7 +364,7 @@ qui ne sont pas suivis du mot `fat` précédé d'un espace. ### 4.3 Recherche en arrière positive La recherche en arrière positive est utilisée pour trouver une string précédée d'un schéma. La recherche en arrière positive se note -`(?<=...)`. Par exemple, l'expression régulière `(?<=[T|t]he\s)(fat|mat)` signifie: trouve tous les mots `fat` ou `mat` de la string qui +`(?<=...)`. Par exemple, l'expression régulière `(?<=[T|t]he\s)(fat|mat)` signifie : trouve tous les mots `fat` ou `mat` de la string qui se trouve après le mot `The` ou `the`.@@ -376,7 +376,7 @@ se trouve après le mot `The` ou `the`. ### 4.4 Recherche en arrière négative La recherche en arrière négative est utilisée pour trouver une string qui n'est pas précédée d'un schéma. La recherche en arrière négative se note -`(? @@ -392,14 +392,14 @@ dans n'importe quel ordre et combinaison et font partie intégrante de la RegExp |Drapeau|Description| |:----:|----| -|i|Insensible à la casse: Définit que la correspondance sera insensible à la casse.| -|g|Recherche globale: Recherche la correspondance dans la string entière.| -|m|Multiligne: Meta-caractère ancre qui agit sur toutes les lignes.| +|i|Insensible à la casse : Définit que la correspondance sera insensible à la casse.| +|g|Recherche globale : Recherche la correspondance dans la string entière.| +|m|Multiligne : Meta-caractère ancre qui agit sur toutes les lignes.| ### 5.1 Insensible à la casse -Le modifieur `i` est utilisé pour faire une correspondance insensible à la casse. Par exemple, l'expression régulière `/The/gi` signifie: la lettre -`T` majuscule, suivie par le caractère `h` minscule, suivi par le caractère `e` minuscule. Et à la fin de l'expression régulière, le drapeau `i` dit au +Le modifieur `i` est utilisé pour faire une correspondance insensible à la casse. Par exemple, l'expression régulière `/The/gi` signifie : la lettre +`T` majuscule, suivie par le caractère `h` minuscule, suivi par le caractère `e` minuscule. Et à la fin de l'expression régulière, le drapeau `i` dit au moteur d'expression régulière d'ignorer la casse. Comme vous pouvez le voir, nous mettons aussi un drapeau `g` parce que nous voulons chercher le schéma dans la string entière. @@ -418,7 +418,7 @@ la string entière. ### 5.2 Correspondance globale Le modifieur `g` est utilisé pour faire une recherche globale (trouver toutes les strings plutôt que de s'arrêter à la première correspondance ). Par exemple, -l'expression régulière `/.(at)/g` signifie: n'importe quel caractère sauf le retour de ligne, suivi par le caractère `a` minuscule, suivi par le caractère +l'expression régulière `/.(at)/g` signifie : n'importe quel caractère sauf le retour de ligne, suivi par le caractère `a` minuscule, suivi par le caractère `t` minuscule. Grâce au drapeau `g` à la fin de l'expression régulière maintenant il trouvera toutes les correspondances de toute la string.@@ -437,7 +437,7 @@ l'expression régulière `/.(at)/g` signifie: n'importe quel caractère sauf le Le modifieur `m` est utilisé pour trouver une correspondance multiligne. Comme mentionné plus tôt, les ancres `(^, $)` sont utilisés pour vérifier si le schéma se trouve au début ou à la fin de la string. Mais si nous voulons que l'ancre soit sur chaque ligne nous utilisons le drapeau `m`. Par exemple, l'expression régulière -`/at(.)?$/gm` signifie: le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par optionnellement n'importe quel caractère à part le retour de ligne. +`/at(.)?$/gm` signifie : le caractère `a` minuscule, suivi par le caractère `t` minuscule, suivi par optionnellement n'importe quel caractère à part le retour de ligne. Grâce au drapeau `m` maintenant le moteur d'expression régulière trouve le schéma à chaque début de ligne dans la string.From 9968a235b6bc12b95fbfe3fb9a09a4daf7bcdae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Borbo=C3=ABn?=Date: Sat, 19 Aug 2017 11:15:19 +0200 Subject: [PATCH 034/212] Homogenized images (#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * RegExp image for French plus * Some typo corrected * Typographics rules (as space before :) * égual - égal * Images folder added, img src updated * § formatted to 80 lines --- README-es.md | 2 +- README-fr.md | 2 +- README-ja.md | 2 +- README.md | 282 ++++++++++++++++++------------ img/img_original.png | Bin 0 -> 6634 bytes img/regexp-en.png | Bin 0 -> 32144 bytes img/regexp-es.png | Bin 0 -> 34234 bytes img/regexp-fr.png | Bin 0 -> 32922 bytes img/regexp.svg | 397 +++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 573 insertions(+), 112 deletions(-) create mode 100644 img/img_original.png create mode 100644 img/regexp-en.png create mode 100644 img/regexp-es.png create mode 100644 img/regexp-fr.png create mode 100644 img/regexp.svg diff --git a/README-es.md b/README-es.md index 6988406c..82ec6f66 100644 --- a/README-es.md +++ b/README-es.md @@ -21,7 +21,7 @@ Imagina que estas escribiendo una aplicación y quieres agregar reglas para cuan
-
De la expresión regular anterior, se puede aceptar las cadenas 'john_doe', 'jo-hn_doe' y 'john12_as'. La expresión no coincide con el nombre de usuario 'Jo', porque es una cadena de caracteres que contiene letras mayúsculas y es demasiado corta. diff --git a/README-fr.md b/README-fr.md index 729e2dda..126ca62b 100644 --- a/README-fr.md +++ b/README-fr.md @@ -24,7 +24,7 @@ le pseudonyme à contenir des lettres, des nombres, des underscores et des trait de caractères dans le pseudonyme pour qu'il n'ait pas l'air moche. Nous utilisons l'expression régulière suivante pour valider un pseudonyme:+
![]()
-
L'expression régulière ci-dessus peut accepter les strings `john_doe`, `jo-hn_doe` et `john12_as`. Ça ne fonctionne pas avec `Jo` car diff --git a/README-ja.md b/README-ja.md index bdce2acc..8fb870b2 100644 --- a/README-ja.md +++ b/README-ja.md @@ -27,7 +27,7 @@+
![]()
-
この正規表現によって `john_doe, jo-hn_doe, john12_as` などは許容されることになります。 diff --git a/README.md b/README.md index 7a05ff3b..823ce08c 100644 --- a/README.md +++ b/README.md @@ -15,20 +15,26 @@ > Regular expression is a group of characters or symbols which is used to find a specific pattern from a text. -A regular expression is a pattern that is matched against a subject string from left to right. The word "Regular expression" is a -mouthful, you will usually find the term abbreviated as "regex" or "regexp". Regular expression is used for replacing a text within -a string, validating form, extract a substring from a string based upon a pattern match, and so much more. +A regular expression is a pattern that is matched against a subject string from +left to right. The word "Regular expression" is a mouthful, you will usually +find the term abbreviated as "regex" or "regexp". Regular expression is used for +replacing a text within a string, validating form, extract a substring from a +string based upon a pattern match, and so much more. + +Imagine you are writing an application and you want to set the rules for when a +user chooses their username. We want to allow the username to contain letters, +numbers, underscores and hyphens. We also want to limit the number of characters +in username so it does not look ugly. We use the following regular expression to +validate a username: -Imagine you are writing an application and you want to set the rules for when a user chooses their username. We want to -allow the username to contain letters, numbers, underscores and hyphens. We also want to limit the number of -characters in username so it does not look ugly. We use the following regular expression to validate a username:+
![]()
-
-Above regular expression can accept the strings `john_doe`, `jo-hn_doe` and `john12_as`. It does not match `Jo` because that string -contains uppercase letter and also it is too short. +Above regular expression can accept the strings `john_doe`, `jo-hn_doe` and +`john12_as`. It does not match `Jo` because that string contains uppercase +letter and also it is too short. ## Table of Contents @@ -61,8 +67,9 @@ contains uppercase letter and also it is too short. ## 1. Basic Matchers -A regular expression is just a pattern of characters that we use to perform search in a text. For example, the regular expression -`the` means: the letter `t`, followed by the letter `h`, followed by the letter `e`. +A regular expression is just a pattern of characters that we use to perform +search in a text. For example, the regular expression `the` means: the letter +`t`, followed by the letter `h`, followed by the letter `e`.+
"the" => The fat cat sat on the mat. @@ -70,9 +77,11 @@ A regular expression is just a pattern of characters that we use to perform sear [Test the regular expression](https://regex101.com/r/dmRygT/1) -The regular expression `123` matches the string `123`. The regular expression is matched against an input string by comparing each -character in the regular expression to each character in the input string, one after another. Regular expressions are normally -case-sensitive so the regular expression `The` would not match the string `the`. +The regular expression `123` matches the string `123`. The regular expression is +matched against an input string by comparing each character in the regular +expression to each character in the input string, one after another. Regular +expressions are normally case-sensitive so the regular expression `The` would +not match the string `the`."The" =>