[英]RegEx match certain string until next occurence of this string
I need to match a string (let's name it "/export/home") and everything that follows (including optional new lines) until the next occurence of this string.我需要匹配一个字符串(让我们将其命名为“/export/home”)和后面的所有内容(包括可选的新行),直到该字符串下一次出现。
I tried /(/export/home. \\n . )(.) / but it won't match the correct set from string to string.我试过/(/export/home.\\n . )(.) / 但它不会匹配从字符串到字符串的正确设置。
Example:例子:
/export/home/bla "123" "bla" test 1
/export/home/bla "123" "bla" test 2
/export/home/bla "123" "bla" test 3
test4
test5
/export/home/bla "123" "bla" test 6
/export/home/bla "123" "bla" test 7
/export/home/bla "123" "bla" test 8
test9
/export/home/bla "123" "bla" test 1
Everything and including from /export/home until the next /export/home should be matched.从 /export/home 到下一个 /export/home 的所有内容都应该匹配。 Any help is appreciated, thanks in advance任何帮助表示赞赏,提前致谢
You may use a tempered greedy token :您可以使用温和的贪婪令牌:
(?s)/export/home(?:(?!/export/home\b).)*
^^^^^^^^^^^^^^^^^^^^^^^^
See the regex demo查看正则表达式演示
The (?s)
will make .
(?s)
将使.
match any char including line break chars, /export/home
will match /export/home
and (?:(?!/export/home).)*
will match any char ( .
), zero or more occurrences ( *
) that does not start a /export/home
literal char sequence.匹配任何字符,包括换行符, /export/home
将匹配/export/home
和(?:(?!/export/home).)*
将匹配任何字符 ( .
),零次或多次出现 ( *
)不启动/export/home
文字字符序列。
If you unroll the pattern, it will look like如果你 展开图案,它看起来像
/export/home/[^/]*(?:/(?!export/home/)[^/]*)*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.