You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
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:
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.
Activity
derek73 commentedon Aug 9, 2020
This seems like a good idea and not too hard to do.
derek73 commentedon Jul 1, 2026
Thanks for the detailed writeup! Rather than patching
regexes.py/parser.pydirectly (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 thatparse_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:Note
constants=Nonegives thisHumanNameinstance its ownConstantscopy so the change doesn't leak into other instances/threads; if you want it applied globally, register onnameparser.config.CONSTANTSinstead.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.
docs: add missing v1.3.0 changelog entries for #100, #166, #187, #188, …