DEV Community

Randy Rivera
Randy Rivera

Posted on

Check For Mixed Grouping Of Characters

  • 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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)