re = /(?:(\w)(?=(?:(?:[^~]+)~)*(?:\1=(\d{96}))))|~[^\n]+/m
str = 'enter any text you want here and use the substitution in the second part to decode it back to words
~t=483448348344834834444448344444448344444483444444985648348344834483483444444834444448344444444454~h=323483448348344834483483444444834444444444444341985648348344834483483444444834444448344444444454~i=013448348348344444834483483444444834444444444432985648348344834483483444444834444448344444444454~s=956483444834483448348344444483444444834444444687985648348344834483483444444834444448344444444454~a=655648348344444454834834483483444444834444444444985648348344834483483444444834444448344444444454~e=564834448348344834483483444444834444444444445655985648348344834483483444444834444448344444444454~b=676548344834834448344834834444448344444444444468985648348344834483483444444834444448344444444454~c=766548484834483483444444834444443483444444344467985648348344834483483444444834444448344444444454~d=984834483483444444483448348344444483444444446569985648348344834483483444444834444448344444444454~f=985648348344834483483444444834444448344444444454985648348344834483483444444834444448344444444454~g=365483444848344834834444448344444434834444444654985648348344834483483444444834444448344444444454~j=456544848344834834444448344444434834444448344472985648348344834483483444444834444448344444444454~k=365483483484834483483444444834444443444444444692985648348344834483483444444834444448344444444454~l=064834483484834483483444444834444443444444445602985648348344834483483444444834444448344444444454~m=648344448348344444483448348344444483444444456566985648348344834483483444444834444448344444444454~n=483483444448344834834444448344444444483483444444985648348344834483483444444834444448344444444454~o=885554483483444448344834834444448344444444834448985648348344834483483444444834444448344444444454~p=996548344834483483444444834444444834834444444469985648348344834483483444444834444448344444444454~q=876564834834848344834834444448344444434444444446985648348344834483483444444834444448344444444454~r=1164834834834483483444444834444444444445483444661985648348344834483483444444834444448344444444454~u=4933483483484834483483444444834444443444444444351985648348344834483483444444834444448344444444454~v=874834834444448344834834444448344444444483444548985648348344834483483444444834444448344444444454~w=344834483483483448348344444483444444444444444563985648348344834483483444444834444448344444444454~x=954794834448344834834444448344444448348344444449985648348344834483483444444834444448344444444454~y=844834483483483448348344444483444444444444443399985648348344834483483444444834444448344444444454~z=389483444483483444444533985648348344834483483444444834444448344444444454~'
subst = '$2'
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
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