We are given
str =<<-END
[example.com]
10.100.251.1
10.100.251.2
10.100.251.3
[example.net]
10.100.251.22
10.100.251.33
END
#=> "[example.com]\n10.100.251.1\n10.100.251.2\n10.100.251.3\n[example.net]\n10.100..."
The question is a bit confusing in that the desired output is said to be
[example.net]
10.100.251.22
10.100.251.33
but that is also what is to be deleted. What follows returns the lines that are not deleted, but it would be a simple matter to change it to return the deleted bits. Also, the question doesn't make clear if the string "[example.net]"
is known or if it's just an example of what might follow the "[example.com]"
"block". Nor is it clear if there are exactly two "blocks", as in the example, or there could be one or more than two blocks.
If you know "[example.net]"
immediately follows the "[example.com]"
block, you could write
r = /
\[example\.com\] # match string
.*? # match any number of characters, lazily
(?=\[example\.net\]) # match string in positive lookahead
/mx # multiline and free-spacing modes
puts str[r]
[example.com]
10.100.251.1
10.100.251.2
10.100.251.3
If you don't know what follows the "[example.com]"
"block", except that that the first line of the following block, if there is one, contains at least one character other than a digit or period, you could write
r = /
\[example\.com\]\n # match string
.*? # match any number of any characters, lazily
(?:[\d.]*\n) # match a string containing > 0 digits and periods,
# followed by a newline, in a non-capture group
+ # match the above non-capture group > 0 times
/x # free-spacing mode
puts str[r]
[example.com]
10.100.251.1
10.100.251.2
10.100.251.3