Extract text before first comma with regex

regex, ruby

Solution

Match everything from the beginning of the string until the first comma:

^(.+?),

Problem

I want to extract text before first comma (first and last name) from strings like: ``` John Smith, RN, BSN, MS Thom Nev, MD Foo Bar, MD,RN ``` I tried with regex: ``` (.*)\s(.*),\s ``` but this doesn't work for all situations. How to achieve this?

Original source