re = /(?(DEFINE)
(?P<realEnd>
(?(3)\>)
(?(4)\))
(?(5)\])
(?(6)\})
(?(7)\7)
)
)
#Ограничитель 1
((\<)|(\()|(\[)|(\{)|
((?=[[:ascii:]])[^\s\w\\\)\]\}\>]))
#Шаблон
(
(?:
\\. | # что-то экранированое ИЛИ
[\w\d\s]++ | # литералы, которые не могут быть ограничителем ИЛИ
(?!(?P>realEnd)). # что угодно кроме ограничителя
)*+
)
#Ограничитель 2
(?P>realEnd)
#Модификаторы шаблонов
#PHP [mixXsuUAJ] JavaScript [gmi] python [gmixsu]
((?:[mixXsuUAJ]*)|(?(?=.*?[mixXsuUAJ]+)[mixXsuUAJ]+))/x
str = 'test $ffsd\\$ggg\\\\\\\\\\\\\\\\$iU'
# 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