re = /(datatype\s+: 4\b(?:(?!datatype\s+: \d)[\s\S])*?(maxlength\s+:\s0\b))/
str = 'field {
id : 536870914
name : Set Field (Submit Mode)
datatype : 4
fieldtype : 1
create-mode : 2
option : 2
timestamp : 1489159658
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 0
clob-store-opt : 0
menu-style : 1
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}
field {
id : 536870915
name : Schema Name
datatype : 4
fieldtype : 1
create-mode : 2
option : 1
timestamp : 1165057260
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 30
clob-store-opt : 0
menu-style : 1
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}
field {
id : 536870916
name : Type
datatype : 4
fieldtype : 1
create-mode : 2
option : 1
timestamp : 1165057260
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 30
clob-store-opt : 0
menu-style : 2
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}
field {
id : 536870917
name : Set Field (Query Mode)
datatype : 4
fieldtype : 1
create-mode : 2
option : 2
timestamp : 1489159658
owner : John Smith
last-changed : John Smith
length-units : 0
maxlength : 0
clob-store-opt : 0
menu-style : 1
qbe-match-op : 1
fulltext-optns : 0
permission : 12\\1
}'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html