I would use the following regular expression:
/Error\sCode\s\d{1,3}/
Or, with named groups:
/Error\sCode\s(?<error_code>\d{1,3})/
The latter will record the error code, number, under the named group. Note that \s matches spaces, but this is not necessary if the x flag is not specified. You can access the following entries:
str = "Error Code 0\nError Code 45\nError Code 190" error_codes = str.lines.map{|l|l.match(regex)[:error_code]} #=> ["0", "45", "190"]
source share