Created
August 17, 2023 15:46
-
-
Save suhailgupta03/a92bb11e35fb80ca6ad158fb79aaa3ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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