Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 17, 2023 15:35
Show Gist options
  • Save suhailgupta03/470d592ca3bb015bec61e849a4849496 to your computer and use it in GitHub Desktop.
Save suhailgupta03/470d592ca3bb015bec61e849a4849496 to your computer and use it in GitHub Desktop.
let string = "Recently India celebrated its Independence Day."
// Problem: I want to know if in the above sentence "ebr" occurs togethor or not
// Solution: Use regex to find the pattern
let regex = /ebr/
// regular expression means a pattern
// pattern that we want to find
// Here the pattern is ebr
// regular expression starts with / and ends with /
// Now we have to find if the pattern occurs in the string or not
let out = regex.test(string)
// test method returns true if the pattern is found in the string
// else it returns false
console.log(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment