Confusion in regex

This is the example:

This is the part I don’t understand:

Why will the match return that?

That’s how those 2 functions work, the test() only evaluate if the regex is matching so it only outputs True (if the string matches with the regex ) or False, while the match() function literally returns the matched elements in your string IF the regex is correct

I know that. The thing I can’t understand is why return: [“regex regex”, “regex”]?

oh the first item in the array is the matched string, while the second one is the capturing group, in this example is “regex” in “regex regex” or another example could be :
/(foo)/ matches and remembers “foo” in “foo bar”.

1 Like

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