Regular expression,



It gives gopalan as output, but I need to replace until first “.”
(i.e)output would be raja.gopalan.

How would I do this?

Use “sub”, and the non-greedy operator: “?”


Thank you Joel P.

hi Rob B.

OK, thank you.

On 2013-Dec-18, at 04:23 , Joel P. [email protected] wrote:

Use “sub”, and the non-greedy operator: “?”


Posted via

Alternatively, you could match all non-. characters up to the first .


\A anchors the match to the beginning of the string
[^.] matches any character that isn’t a .

irb2.0.0> “M.raja.gopalan”.sub(/\A[^.]*./,‘’)
#2.0.0 => “raja.gopalan”