Naigel
Naigel

Reputation: 9644

find all substrings matching the pattern

I need to find all substrings like "something.somethingElse.get()" in a long string. I'm using match function in this way

myString.match(/\S+\.\S+\.get\(\)/);

It works, but returns only the first occurrence, so I have to split the string in some way to eliminate the firt part and repeat match again. Is there a more efficient way to do this? I mean something like a search function that returns all substring in an array or an object

Upvotes: 0

Views: 1714

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

myString.match(/\S+\.\S+\.get\(\)/gi);

You need to add global switch at the end of your regex.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/match (thanx, vcsjones)

Upvotes: 3

Related Questions