0% found this document useful (0 votes)
49 views10 pages

Regular Expressions

The document discusses regular expressions including special characters, quantifiers, character classes, grouping and alternatives, lookarounds, and methods. It covers common regex patterns and sub-expressions that can be used to match text at the beginning, end, or boundaries. Examples are provided to demonstrate how different quantifiers and lookarounds work in both greedy and lazy modes.

Uploaded by

Batool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views10 pages

Regular Expressions

The document discusses regular expressions including special characters, quantifiers, character classes, grouping and alternatives, lookarounds, and methods. It covers common regex patterns and sub-expressions that can be used to match text at the beginning, end, or boundaries. Examples are provided to demonstrate how different quantifiers and lookarounds work in both greedy and lazy modes.

Uploaded by

Batool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Regular Expression

Agenda

 Regular Expression Pattern


 Special characters
 Quantifiers
 Character Classes
 Grouping and Alternatives
 Lookarounds
 Regex (Regular Expression Class)
 IsMatch(string)
Regex | Special Characters

 Capital letters have an opposite meaning of small letters


Sub-expression Matches Sub-expression Matches
^ matches at the beginning of the string or line. \d match the digit character
$ Word before this element matches at the end of the \w match any alphanumeric and underscore
line or string. character
\s white-space characters \D  match the non-digit character
\S non white-space characters \W match the any non-word character
\n match a newline character \ Escape character
\b Match text boundary
Regex | Quantifiers

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

text  Regex uses a search Result


Greedy pattern Lazy Result
expression Expression
Visit https:\\ https? https https?? http
Call 7343378- 734\d* 7343378 734\d*? 734
79
7343378-79 734\d+ 7343378 734\d+? 7343
7343378-79 734{2,} 7343378 734{2,}? 73433
7343378-79 734{2,7} 7343378 734{2,7}? 73433
Regex | Character Classes

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

Sub-expression Name Matches


(?=check) Positive Lookahead Asserts that what immediately follows the current position in the string is
"check"
(?<=check) Positive Lookbehind Asserts that what immediately precedes the current position in the string is
"check"
(?!check) Negative Lookahead Asserts that what immediately follows the current position in the string is
not "check"
(?<!check) Negative Lookbehind Asserts that what immediately precedes the current position in the string is
not "check"

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

 IsMatch(String): return true/false


 Match
 Matches
 Replace
 Split

You might also like