The string.match() is used to find substrings matching a pattern, the RegExp. But when you call this expecting a multiple return, you'll only get the first match.
test = "Cats don't eat catfish. Not my cat";
System.log (test.match("cat"));
will return only one element in array: "cat" - the first match found in catfish.
By expanding the RegExp with modifiers you will receive all results (maybe you know them from JavaScript).
test = "Cats don't eat catfish. Not my cat";
System.log (test.match(new RegEx("cat", "g")));
returns "cat,"cat" for both cat in string.
Using "i" will return "Cat".
And the combination gi "Cat", "cat", "cat"
- i for case independend search
- g for global search
- gi as combination of both
This is the expected behavior mentioned in all tutorials.
Regards, Andreas