RegEx expert advice needed

  1. 5 days ago

    Tiago R

    May 21 Testers Planet Earth

    Hi ReEx experts!

    I am trying to match the name and nickname of a person whose records are provided in this format:

    Lastname, Firstname (nickname) (ID)

    Ex: Doe, Robert (Bob) (1234)

    Nickname is optional so it could be there, or not.
    I want to extract just the part of the name that precedes the ID, including the nickname if it's there. Ex: Doe, Robert (Bob) . A name without a nickname should also be captured.

    This is the closest I could get to it, but I'm still missing the trailing parenthesis for the nickname:

    [a-zA-Z0-9,().!? ]*[^\(0-9\)]

    Any idea about what I need to add to capture the full name/nickname? Thanks!

    Try this:

    \b[^,\s]+, [^(\s]+( \([^)]+\))?(?= \(\d+\))
  2. Jeremie L

    May 21 Testers, Xojo Pro, XDC Speakers, MVP Europe (France) - packr.app
    Edited 5 days ago

    I don't have a solution but already see an issue with [a-zA-Z...
    That will not match names with diacritics such as éèàáç, neither ' such as O'Connor

    If you absolutely need RegEx then wait for an expert to come in, @Kem T maybe?

    I would use a different approach by splitting the string using "(" character and then joining without the last n-th field.

  3. Kem T

    May 21 Testers, Xojo Pro, XDC Speakers, MVP Connecticut

    If I understand, the two possible forms before the id that you want to capture are:

    Doe, Robert
    Doe, Robert (Bob)

    Is that it?

  4. Tiago R

    May 21 Testers Planet Earth

    @Kem T If I understand, the two possible forms before the id that you want to capture are:

    Doe, Robert
    Doe, Robert (Bob)

    Is that it?

    Exactly!

  5. Kem T

    May 21 Testers, Xojo Pro, XDC Speakers, MVP Connecticut

    I have a pattern in mind but won't be able to test it for about an hour or two. I'll post then.

  6. Kem T

    May 21 Testers, Xojo Pro, XDC Speakers, MVP Answer Connecticut
    Edited 5 days ago

    Try this:

    \b[^,\s]+, [^(\s]+( \([^)]+\))?(?= \(\d+\))
  7. Tiago R

    May 21 Testers Planet Earth

    @Kem T Try this:

    \b[^,\s]+, [^(\s]+( \([^)]+\))?(?= \(\d+\))

    Thank you Kem!!

or Sign Up to reply!