Search code examples
regexpcre

Regex (PCRE) exclude certain words from match result


I need to get only the string with names that is in Bold:

author={Trainor, Sarah F and Calef, Monika and Natcher, David and Chapin, F Stuart and McGuire, A David and Huntington, Orville and Duffy, Paul and Rupp, T Scott and DeWilde, La'Ona and Kwart, Mary and others},

Is there a way to skip all 'and' 'others' words from match result?

Tried to do lots of things, but nothing works as i expect

(?<=\{).+?(?<=and\s).+(?=\})

Solution

  • Instead of using omission, you could be better off by implementing rules which expect a specific format in order to match the examples you've provided:

    ([A-Z]+[A-Za-z]*('[A-Za-z]+)*, [A-Z]? ?[A-Z]+[A-Za-z]*('[A-Za-z]+)*( [A-Z])?)
    

    https://regex101.com/r/9LGqn3/3