What I Tried
var test = "asdfdas ABCD EFGH";
var regex = /^\S+( [A-Z]{4})+$/;
// Also tried: /^\S+( [A-Z]{4})+$/g
// And: /^\S+( [A-Z]{4})+?$/g
var matches = test.match(regex);
I made a JSFiddle.
What I Expect
The variable matches
should become this array:
[
"asdfdas ABCD EFGH",
" ABCD",
" EFGH"
]
What I Get
The variable matches
is actually this array:
[
"asdfdas ABCD EFGH",
" EFGH"
]
My Thoughts
My guess is that there's something I'm missing with the capture group and/or $
logic. Any help would be appreciated. (I know I can figure out how to do this in multiple regular expressions, but I want to understand what is happening here.)