我正在寻找解码一个正则表达式。有没有办法检查下面的正则表达式的含义:
^(PC([Y\\d])|GC([Y\\d])|Y|\\d)\\d{4,5}$发布于 2013-03-12 03:32:24
您可以在http://www.myezapp.com/apps/dev/regexp/show.ws或http://www.debuggex.com/上使用正则表达式分析器
^ = start of string
() = capturing groups
[] = character classes
\d = digit in 0-9
\\ = literal backslash
| = OR
{} = count of leading item
$ = end of string发布于 2013-03-12 05:18:05
以下是正在发生的事情的细分。
正则表达式:^(PC([Y\\d])|GC([Y\\d])|Y|\\d)\\d{4,5}$
1. ^ - Beginning of line
2. ( - Beginning of a capture group
3. PC - Finds `PC` exactly
4. ([Y\\d]) - Creates a capture group for a Y or a single digit (0-9)
5. | - This is an OR statement
6. GC - Finds `GC` exactly
7. ([Y\\d]) - Same as 4
8. | - This is an OR statement
9. Y - Finds `Y` exactly
10. | - This is an OR statement
11. \\d - This looks for a single digit (0-9)
12. ) - End of capture group. Lines 3-11 will be in this capture group
13. \\d{4,5} - This will look any digit exactly 4 or 5 times
14. $ - End of line其中有3个捕获组:
1. (PC([Y\\d])|GC([Y\\d])|Y|\\d)
2. ([Y\\d]) (The first one)
3. ([Y\\d]) (The second one)这是一个有效的匹配列表(任何数字都可以找到,我只是用123456来显示可以有多少个数字位):
的
Here是指向RegExr的链接,其中包含每个匹配的捕获组的说明。
此外,\\d中使用双\的原因是为了避开\。并不是所有的语言都需要它,据我所知,有一些语言需要3。如果你注意到上面的RegExr,我删除了它们,这样RegExr就可以正确地解析正则表达式。
发布于 2017-07-05 21:03:44
https://stackoverflow.com/questions/15346955
复制相似问题