[Ruby] Delete the specified characters and after from the character string

less than 1 minute read

str = "A30-60_10000"

erase the back

str.sub(/_.*/, "")

Result ↓

=> "A30-60"

erase before

str.sub(/.*_/, "")

Result ↓

"10000"

reference https://qiita.com/flmil/items/8cbfbf49844ddef79000

Tags:

Updated: