Hello! I have a string: “Hello - 1 - World”
irb(main):017:0> a = “Hello - 1 - World”
=> “Hello - 1 - World”
I want to chop off the "Hello - " part. Hello could be any word, so I
want to match it generically.
To match the first minus I do this:
irb(main):018:0> b = a.sub(/\s-\s/, “”)
=> “Hello1 - World”
Good! Now to get rid of the first word I try this:
irb(main):019:0> c = a.sub(/.*\s-\s/, “”)
Bad! It matched to the second minus! Why does sub do this? I thought
it was supposed to match the first occurrence only.