String separated

How to separate this string “ABC_DEFG_HIJK__LMN:1234” to ABCDEFGHIJKLMN
:1234

Thanks,

array=“ABC_DEFG_HIJK__LMN:1234”.split(/[_:]/)
#=>[“ABC”, “DEFG”, “HIJK”, “”, “LMN”, “1234”]
array.pop #=> “1234”
array.join#=>“ABCDEFGHIJKLMN”

or do you want:
“ABC_DEFG_HIJK__LMN:1234”.split(/_/).join
#=>“ABCDEFGHIJKLMN:1234”

CC Chen wrote in post #1009111:

How to separate this string “ABC_DEFG_HIJK__LMN:1234” to ABCDEFGHIJKLMN
:1234

str = ‘ABC_DEFG_HIJK__LMN:1234’
puts str.gsub(’_’, ‘’)

–output:–
ABCDEFGHIJKLMN:1234

string is “”(/"“ABCDEFG”"/1234)""

how to separate ABCDEFG and 1234 in shortly.

CC Chen wrote in post #1009111:

Thanks a lot,

CC Chen wrote in post #1009630:

string is “”(/"“ABCDEFG”"/1234)""

how to separate ABCDEFG and 1234 in shortly.

str = %q{"(/"“ABCDEFG”"/1234)"}

str.scan(/\w+/).each do |match|
puts match
end

–output:–
ABCDEFG
1234