Grouping in regular expressions

1- When I ran this code:

let testStr = "PumpkinPenguin";
let testRegex = /P(engu|umpk)in/;

the result was:
["Pumpkin", "umpk"] , and when I added the global search flag, it changed “umpk” into Penguin. Why is that?

2- Another question regarding the challenge:
It is asking me to do the following:

Fix the regex so that it checks for the names of Franklin Roosevelt or Eleanor Roosevelt in a case sensitive manner and it should make concessions for middle names.

And the solution to the challenge will check Franklin D.Roosevelt for example. What if I don’t want this case to happen (i.e. how can I make a space obligatory between two names whether the middle name is there or not so that something like
Franklin D.Roosevelt or FranklinRoosevelt is not checked and how can I make the middle name take a limit of only one letter and a dot without affect the checkability of the case where we don’t have a middle name so that Franklin Roosevelt is checked and Franklin D. Roosevelt is checked, but Franklin Da. Roosevelt is not checked?

Challenge: Check For Mixed Grouping of Characters

Link to the challenge:

The " g " flag indicates that the regular expression should be tested against all possible matches in a string.

Without the g flag, the regex stops the search, once it has a match.

You get umpk in the array as it is remembered by the capture group (engu|umpk) upon matching Pumpkin.

You can learn more about regex on Regular expressions - JavaScript | MDN (

regex101: build, test, and debug regex is a great tool for debugging regex.

You can use the quantifier ?.

x? (Matches the preceding item “x” 0 or 1 times)

So is this regex /(Franklin|Eleanor) (.\. )?Roosevelt/ true for these cases?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.