0% found this document useful (0 votes)
7 views7 pages

Regex Library (Regular Expressions)

Uploaded by

abhiparasharr
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)
7 views7 pages

Regex Library (Regular Expressions)

Uploaded by

abhiparasharr
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
You are on page 1/ 7

Regex Library (Regular

Expressions)
Introduction:

https://regexr.com/

A regular expression is a way to search through a string of text.

💡 Syntax:

/regular expression/flags

We declare regular expressions in between forward slashes and after the


end, we set a flag.
Some common flags are: global, multiline etc.

We can stack multiple flags like /text/gi This way we can stack global
and case insensitive together.

Regex Library (Regular Expressions) 1


Regular Expression Characters:

Regex Library (Regular Expressions) 2


💡 /e/g //This search for an e in the string

/e+/g //This search for at least one ‘e’, and also searches for multiple in a
row

/e+a/g //This search for a combination of ea only

/e+a?/g//This ? makes the search for ‘a’ optional, anything behind the ?
is considered as optional

Regex Library (Regular Expressions) 3


//This 8 character is a combination of the + and ? character, this
/re*/g

makes search of e optional but if found it can search for as many as


possible

/.at/g//This . searches for any character before ‘at‘ except for a


newline

Regex Library (Regular Expressions) 4


If placed after a character it searches of a singular character.

/\./g When we want to match the real ‘.’

We can also combine special characters ex:

/.+\@/ This gets all characters before the @ symbols

💡 /\w/g

alphabet
This matches any alphabet \W This matches anything that is not a

/\s/gThis matches any whitespace \S This matches anything that is


not a whitespace

/\w{4,}/ This groups words with more than 4 characters

Regex Library (Regular Expressions) 5


💡 Grouping Characters:
We can group characters that we want to search for.

/[a-zA-Z0-9]/g This searches for anything characters inside thee brackets

/(t|T)he/g This also makes a group, | creates a our statement.

/(a|b|c){2,3}/g Can also include {}

/^[A-Za-z0-9]/g This starts checking from the start of the line

/\.$/g This checks from the end of line

Look Ahead and Look Behind:


Continue when free:

Regex Library (Regular Expressions) 6


https://www.youtube.com/watch?v=rhzKDrUiJVk

const paragraph = '[email protected].';


const regex = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/g;
console.log( paragraph.match(regex));
// Expected output: null

Regex Library (Regular Expressions) 7

You might also like