Reputation: 5931
I am trying to capture [dockercloud_servers]
until the beginning of the next [
(the start of redis_servers). However, I don't want to capture the [
last bracket.
I tried doing ?:
but I can't seem to omit that last bracket, any ideas?
Link: https://regex101.com/r/fYRiJR/1
OR:
Regex
(\[dockercloud_servers\]){1}(?:[^ ]+\[)
Content
[dockercloud_servers]
x
y
[redis_servers]
x
x
Upvotes: 0
Views: 49
Reputation: 516
Try this
(\[dockercloud_servers\].*)(?=\[redis_servers])
https://regex101.com/r/wmBoK3/1
Upvotes: 1
Reputation: 6088
You just have to make a Positive Lookahead with [
at the end as the following:
(?:\[dockercloud_servers\]){1}(?:[^ ]+)(?=\[)
Demo: https://regex101.com/r/fYRiJR/3
Or alternatively, you can make your code shorter by writing the beginning of the word, and then use [\s\S]+
to capture the rest until [
\[docker[\s\S]+(?=\[)
Demo: https://regex101.com/r/fYRiJR/4
Upvotes: 1