Sometimes we want to check for groups of characters using a Regular Expression and to achieve that we use parentheses ().
Below I will give you an example of this. I have a regex so that it checks for the names of Franklin Roosevelt or Eleanor Roosevelt in a case sensitive manner and makes concessions for middle names.
Then I have a code so that the regex that I have created is checked against myString and either true or false is returned depending on whether the regex matches.
let myString = "Franklin D. Roosevelt";
let myRegex = /(Eleanor|Franklin).*Roosevelt/;
let result = myRegex.test(myString);
console.log(result); will display true
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)