Regular Expressions
Regular Expressions
Agenda
Sub-expression
Matches
Greedy Lazy
? ?? Match preceding's 0 or one time
* *? Match preceding's 0 or more times
+ +? Match preceding's one or more times
{n} {n}? match the preceding character exactly n times.
{n,} {n,}? match the preceding character at least n times.
{n,m} {n,m}? match the preceding character from n to m times.
Regex | Quantifiers
Sub-expression Matches
[abc134] Match any character between []
[a-z] Match any character between a and z
[a-zA-Z0-9] Match any character between a-z, A-Z, and 0-9
[^abc] Match all except what comes after ^
Regex | Grouping & Alternatives
Sub-expression Matches
() Used for group expression
(a|b) The operator | represents an alternatives. a or b
(com|org|ye) Match either com, org, or ye
(?(exp) yes|no) If expression is matched it gives yes otherwise it gives no.
Regex | Lookarounds
Example: the pattern \d+(?=A) applied for the string “133,456A,787” will return “456”
Regex | Password Strength | Example
((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})
Any character
Any character (0 or more) then a digit
Regex | Methods