Hallo,

How can i use Regex to match names in different files.

e.g. i have 3 files with names. i need to link the matching names in the different file.

any ideas.

Dani AI

Generated

This thread is about matching names across files when Dutch prefixes appear in different forms. gave the examples v/d Grote and van den Grote and is correct that a plain equality check can work — but only after canonicalizing names. Practical steps: Unicode-normalize and strip accents, lowercase, remove punctuation/extra spaces, and normalize common prefix variants (v/d, vd, v., van, van den) into a single canonical prefix or remove it depending on your matching rule.

A compact Python approach: extract prefix + core surname with a regex, normalize accents, then rebuild a canonical string to use as the key when aggregating names from multiple files.

import re
import unicodedata

PREFIX_RE = re.compile(r'^(?:\s*(v\s*/\s*d|vd|v\.|van(?:\s+den)?)\s+)?(.+)$', re.I)

def strip_accents(s):
    return ''.join(c for c in unicodedata.normalize('NFKD', s) if not unicodedata.combining(c))

def normalize(name):
    s = strip_accents(name).lower().strip()
    m = PREFIX_RE.match(s)
    prefix = (m.group(1) or '').replace('/', ' ').strip() if m else ''
    core = (m.group(2) or s)
    core = re.sub(r'[\W_]+', ' ', core).strip()
    if prefix in ('v d','vd','v.'):
        prefix = 'van den'
    return (prefix + ' ' + core).strip()

Use the returned canonical value as the dictionary key when scanning each file; names that map to the same key are matches. For fuzzy or OCR-affected data, consider difflib.get_close_matches or a Levenshtein-based library. Beware: cultural name rules vary — sometimes prefixes are ignored for sorting, sometimes not — so validate expansions (e.g., v.van vs v/dvan den) against your dataset.

Python regex docs: https://docs.python.org/3/library/re.html. Background on Dutch name prefixes: https://en.wikipedia.org/wiki/Dutch_name.

Recommended Answers

All 3 Replies

but why do u want a regex for that ?

use an if condition, get each file name, use.ToLower() or ToUpper, n then compare if they are equal.

This is what i understood as your requirement.

what is the Regex for a name like (v/d Grote) or (van den Grote). these are dutch surnames

So, you want one Regex to be applied to multiple files?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.