What is a regex that extracts the names from these sets and ignore the comma, ampersand,…
- User
What is a regex that extracts the names from these sets and ignore the comma, ampersand, and "and" phrase?
Bosko, Bunny Bugs Bunny and Daffy Duck Bosko and Bunny Bosko, Porky Pig & Bugs Bunny Porky Pig
Assistant
Here is a regex that will extract the names from those string sets:
(?:[A-Za-z]+(?:\s[A-Za-z]+)*)(?:,|and|&|\s)To break this down:
-
(?:[A-Za-z]+(?:\s[A-Za-z]+)*)matches one or more word characters followed by optional repeating instances of a space and one or more word characters. This matches each name. -
(?:,|and|&|\s)matches either a comma, the word "and", an ampersand, or a space. This allows us to split on those delimiters.
So this will find and capture the individual names while ignoring the delimiters.
For your test strings, it would extract:
Bosko Bunny Bugs Bunny
Daffy Duck Bosko Bunny Bosko Porky Pig Bugs Bunny Porky Pig-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.