如何查找变量中的每个字符串是否具有正则表达式

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

我很难在使用变量的地方实施完整性检查

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

所以问题是我想循环遍历这个变量和包含正则表达式“^/apps/[^/]+/i18n/?.*”的每个字符串 - 这意味着应该匹配具有 apps/something/i18n 的所有内容,如果它以 /content 开头。如果不是则必须抛出异常。

如何循环一个变量,其中每个项目由 space 分隔,并检查这 2 个正则表达式是否适用,否则会抛出异常?

我理解这可能是一个非常初学者的问题,但我无法理解它。

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