0% found this document useful (0 votes)
3 views5 pages

Regex JavaScript Presentation-2

A Regular Expression (Regex) in JavaScript is a pattern used for searching, validating, and manipulating text strings. Common applications include email validation, password strength checking, and phone number verification, with specific syntax and symbols for constructing patterns. Additionally, Regex supports flags for case sensitivity and search modes, along with methods for testing and manipulating strings.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Regex JavaScript Presentation-2

A Regular Expression (Regex) in JavaScript is a pattern used for searching, validating, and manipulating text strings. Common applications include email validation, password strength checking, and phone number verification, with specific syntax and symbols for constructing patterns. Additionally, Regex supports flags for case sensitivity and search modes, along with methods for testing and manipulating strings.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Regular Expressions (Regex) in JavaScript

1. What is a Regular Expression?

A Regular Expression (Regex) is a pattern used to search, validate, and manipulate text strings in
JavaScript.

Common Uses:

1 • Email validation
2 • Password strength checking
3 • Phone number verification
4 • Extracting data from text
2. Regex Syntax in JavaScript

1 Literal Syntax (Recommended for Performance):


2 let regex = /pattern/;
4 Constructor Syntax:
5 let regex = new RegExp('pattern');
3. Important Symbols

1 . -> Any character


2 * -> 0 or more times
3 + -> 1 or more times
4 ? -> 0 or 1 time
5 ^ -> Start of string
6 $ -> End of string
7 \d -> Digit
8 \w -> Letter or digit
9 \s -> Whitespace
4. Example: Email Validation

Example Regex: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-z]{2,}$/

1 ^ -> Start
2 + -> At least one character
3 @ -> Required symbol
4 \. -> Dot
5 $ -> End
5. Flags and Methods

1 Flags:
2 i -> Ignore case
3 g -> Global search
4 m -> Multiline
6 Methods:
7 [Link](string)
8 [Link](regex)
9 [Link](regex, newValue)

You might also like