문제

I have an array list of email address and i want to delete eveything after the ";"

i tried chomp. but that didnt seem to work.

How would i loop through the array and remove everything after the ";" in my view.

도움이 되었습니까?

해결책

Try:

["aaaa;bbb"].map { |e| e.gsub(/;.*/, ';') }

From documentation: gsub returns a copy of str with the all occurrences of pattern substituted for the second argument.

So this regexp will match ; and any character after, so you have to pass ; as second argument.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top