i
Table of Contents
Tutorial..........................................................................1
1. Regular Expression Tutorial..............................................................................3
2. Literal Characters................................................................................................6
3. First Look at How a Regex Engine Works Internally...................................9
4. Character Classes or Character Sets...............................................................11
5. The Dot Matches (Almost) Any Character...................................................16
6. Start of String and End of String Anchors...................................................19
7. Word Boundaries..............................................................................................24
8. Alternation with The Vertical Bar or Pipe Symbol......................................26
9. Optional Items...................................................................................................28
10. Repetition with Star and Plus........................................................................30
11. Use Round Brackets for Grouping..............................................................34
12. Named Capturing Groups.............................................................................40
13. Unicode Regular Expressions.......................................................................43
14. Regex Matching Modes..................................................................................49
15. Atomic Grouping and Possessive Quantifiers...........................................51
16. Lookahead and Lookbehind Zero-Width Assertions...............................58
17. Testing The Same Part of a String for More Than One Requirement...63
18. Continuing at The End of The Previous Match........................................66
19. If-Then-Else Conditionals in Regular Expressions...................................68
20. Adding Comments to Regular Expressions...............................................70
Examples.....................................................................71
1. Sample Regular Expressions...........................................................................73
2. Matching Floating Point Numbers with a Regular Expression.................75
3. How to Find or Validate an Email Address.................................................77
4. Matching a Valid Date......................................................................................82
5. Matching Whole Lines of Text.......................................................................84
6. Deleting Duplicate Lines From a File............................................................86
8. Find Two Words Near Each Other...............................................................88