WhoAmI
WhoAmI

Reputation: 1133

How to find if each string in a variable has a regex

I'm struggling with implementing sanity check where we use a variable

def test = "/apps/damm/i18n /apps/dfdf/i18n /apps/fdf/i18n /apps/bsam/i18n /content"

So the issue is that I want to loop over this variable and for each of the string that contains as a regex " ^/apps/[^/]+/i18n/?.*" - Meaning everything that has apps/something/i18n should be matched and if it starts with /content. If not then have to throw a exception.

How do you loop over a variable with multiple strings for each item seperated by space and check if those 2 regexes apply else throw exception?

I understand it maybe a very beginner question, but I couldn't get my head around it.

Upvotes: 0

Views: 49

Answers (1)

daggett
daggett

Reputation: 28599

def test = "/apps/damm/i18n  /apps/dfdf/i18n /apps/fdf/i18n /apps/bsam/i18n /content"
assert ! test.split(/\s+/).find{ !(it ==~ '/apps/.*/i18n|/content.*') }

Upvotes: 2

Related Questions