解碼正則表達式
回答
你可以在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
這裏是一個向下突破的發生了什麼。
正則表達式:^(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來說明如何有效匹配(任意數量會被發現的列表有很多地方可以):
- PCY1234
- PCY12345
- PCY1234
- PCY12345
- PC12345
- PC123456
- GC12345
- GC123456
- GCY1234
- GCY12345
- Y1234
- Y12345
Here是具有用於每個匹配捕獲基團的解釋來RegExr的鏈接。
此外,中雙\
的原因是爲了逃避用於Java的\
。並不是所有的語言都需要這個,據我所知,有一些需要3.如果你注意到上面的RegExr,我刪除了它們,RegExr會正確解析正則表達式。
+1非常詳細! – 2013-03-12 19:22:08
謝謝,這樣做是我教我自己的正則表達式:) – Nick 2013-03-12 22:32:36
Regexper也是分析正則表達式的好工具。
- 1. 解碼HTML實體正則表達式
- 2. Python - 解碼還是正則表達式?
- 3. 正則表達式代碼解釋
- 4. javascript正則表達式解碼atob
- 5. 解釋正則表達式
- 6. 正則表達式{}解析
- 7. 正則表達式理解
- 8. 瞭解正則表達式
- 9. 正則表達式解決
- 10. 正則表達式解析
- 11. 正則表達式解釋
- 12. 正則表達式解釋
- 13. 瞭解正則表達式
- 14. 瞭解正則表達式
- 15. 正則表達式解釋
- 16. 解釋正則表達式
- 17. 瞭解正則表達式
- 18. 瞭解正則表達式?
- 19. 正則表達式解析
- 20. 瞭解正則表達式
- 21. 瞭解正則表達式表達
- 22. 電話號碼正則表達式(正則表達式)在Python
- 23. 正則表達式(正則表達式)
- 24. 正則表達式(正則表達式)
- 25. 正則表達式(正則表達式)
- 26. 密碼正則表達式
- 27. 正則表達式 - 密碼
- 28. 正則表達式編碼
- 29. 正則表達式正則表達式正則表達式使用正則表達式,但不是與Python
- 30. 密碼規則的正則表達式
對不起。我對正則表達式很陌生。你能幫我理解在正則表達式中分組的意義。 – user179516 2013-03-11 19:49:29
@ user179516您遇到哪個特定部位? – 2013-03-11 19:55:48
PC([])和GC([])組看起來與我相似。我想了解爲什麼我們在這裏增加了兩組。 – user179516 2013-03-11 20:04:55