Skip to content

Instantly share code, notes, and snippets.

@suhailgupta03
Created August 17, 2023 15:46
Show Gist options
  • Save suhailgupta03/a92bb11e35fb80ca6ad158fb79aaa3ef to your computer and use it in GitHub Desktop.
Save suhailgupta03/a92bb11e35fb80ca6ad158fb79aaa3ef to your computer and use it in GitHub Desktop.
let string = "Hi! Recently India celebrated its Independence Day."
// If we want to know whether a string starts with a particular word or not,
// we can use ^ symbol in the beginning of the word to check it.
let pattern = /^H/
// ^ is the symbol for 'start of the string'
// by default the matches are case sensitive
// this means that it will be differentiate between 'H'
// and 'h'
console.log(pattern.test(string)) // true
let patternNew = /^h/i
// i is the symbol for 'case insensitive'
// even though the string starts with 'H' and not 'h'
// the pattern will still match
console.log(patternNew.test(string)) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment