re = /pam\.username%([A-Za-z0-9]+)@|\s\(([0-9]+)\)/m
str = 'Sep 11 03:02:00 (1568505720.145620) danted[10402]: info: pass(2): tcp/connect -: pam.username%MyUsername@46.111.111.250.48198 123.12.12.112.1080 -> 123.12.12.112.48198 111.123.123.147.443 (319721)
Sep 11 03:02:00 (1568505720.147471) danted[10402]: info: pass(2): tcp/connect -: pam.username%MyUsername@46.111.111.250.37449 123.12.12.112.1080 -> 123.12.12.112.37449 123.123.123.211.443 (312)
Sep 11 03:02:00 (1568505720.148240) danted[10402]: info: pass(2): tcp/connect -: 111.123.123.147.443 123.12.12.112.48198 -> 123.12.12.112.1080 pam.username%MyUsername@46.111.111.250.48198 (723)
Sep 11 03:02:00 (1568505720.154784) danted[10402]: info: pass(2): tcp/connect -: 123.123.123.211.443 123.12.12.112.37449 -> 123.12.12.112.1080 pam.username%MyUsername@46.111.111.250.37449 (8831)'
subst = ''
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