I have the following logic
def insert_type(type_list, user_input)
case user_input
when user_input == 'library_1'
type_list.slice!('library_' + RegEx for any digit after library_ and stop right there + '__')
type_list << user_input << '__'
when user_input == 'class_A_2'
type_list.slice!('class_' + RegEx for any digit after class_ and stop right there + _A + '__')
type_list << user_input << '__'
end
end
I tried to do the following
[l][i][b][r][a][r][y][_]\d{0,5} #digit from 0 to 99999
It does work, but there should be a more conventional way out there where I could start with l, and ends with the underscore, then add the number since type_list could be:
puts type_list
=> "username_John__userid_58173__userpass_8adsh20__class_A_2__library_0__"
__(double underscore)?\w+\d{0,5}