Skip to content

Additional nickname delimiter specifications #110

Closed

Description

@aikimark

I've got a large file of names/addresses and decided to try the nameparser library with my name field. I was able to get more of my names parsed correctly by adding two regex patterns and adding these regex patterns to the list.
In regexes.py, added:
('double_apos', re.compile(r"''(.?)''", re.U)),
('apos', re.compile(r"'(.
?)'", re.U)),

In parser.py, added:
re_apos = self.C.regexes.apos
re_double_apos = self.C.regexes.double_apos

In parser.py, changed:
for _re in (re_quoted_word, re_double_quotes, re_parenthesis, re_double_apos, re_apos):

Activity

  1. derek73 commented on Aug 9, 2020

    @derek73
    Owner

    This seems like a good idea and not too hard to do.

  2. derek73 commented on Jul 1, 2026

    @derek73
    Owner

    Thanks for the detailed writeup! Rather than patching regexes.py/parser.py directly (which meant re-forking on every upgrade), as of v1.3.0 there's a supported extension point for exactly this: Constants.extra_nickname_delimiters, added in #190. It's a dict of extra regex patterns that parse_nicknames() runs after the three built-in delimiters (quotes, double quotes, parens), so you can register your patterns at runtime without touching the library source:

    import re
    from nameparser import HumanName
    
    hn = HumanName("John ''Big J'' Smith", constants=None)
    hn.C.extra_nickname_delimiters['double_apos'] = re.compile(r"''(.*?)''")
    hn.C.extra_nickname_delimiters['apos'] = re.compile(r"'(.*?)'")
    hn.parse_full_name()
    
    hn.nickname  # 'Big J'

    Note constants=None gives this HumanName instance its own Constants copy so the change doesn't leak into other instances/threads; if you want it applied globally, register on nameparser.config.CONSTANTS instead.

    These custom patterns go through the same suffix-vs-nickname disambiguation as the built-ins, so something like (Ret) still won't get swallowed as a nickname.

    This shipped in #190 and will be part of the v1.3.0 release. Closing this out — let me know if the new hook doesn't cover your case.

  3. self-assigned this
    on Jul 1, 2026
  4. added this to the v1.3.0 milestone on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions