J. Doe J. Doe - 9 months ago 47
Ruby Question

How to improve my RegEx to get the text before the pattern?

For example I have the next text:

Hello, my name is %{John}.

Now, I want to take all text before
. For this I'm using the next RegEx:


It works, but it includes
this part too. I do not need that. How can I take whole text, but exclude

Answer Source

Try this:


see http://www.rubular.com/r/YHcuSxMIA8