re = /\$(?P<type>(?:v|a|s))?(?P<prop>(?:lang|lang2|lang3|language|codec|format|ch|channels|res|resolution))(?:(?:_(?P<num>\d+))|(?:_(?P<lang>[^_0-9\$\n]+)(?:_(?P<num2>\d+))?))?\$/mi
str = '$alang$
$alang_0$
$acodec$
$acodec_0$
$acodec_jp$
$acodec_jp_0$
$aformat$
$aformat_0$
$aformat_jp$
$aformat_jp_0$
$ach$
$ach_0$
$ach_jp$
$ach_jp_0$
$achannels$
$achannels_0$
$achannels_jp$
$achannels_jp_0$
$codec$
$res$ $vformat$ $aformat_jp$ $ach_0$'
# 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