Skip to content

Add wildcard/glob pattern support for exclude_paths and include_paths#590

Open
akshat62 wants to merge 3 commits intoqlustered:devfrom
akshat62:feature/glob-wildcard-paths
Open

Add wildcard/glob pattern support for exclude_paths and include_paths#590
akshat62 wants to merge 3 commits intoqlustered:devfrom
akshat62:feature/glob-wildcard-paths

Conversation

@akshat62
Copy link
Copy Markdown
Contributor

Adds [*] (match one segment) and [**] (match zero or more segments) wildcard support to exclude_paths and include_paths across DeepDiff, DeepHash, and DeepSearch. Patterns are detected at init time, compiled into GlobPathMatcher objects, and checked alongside exact paths in _skip_this(). Quoted keys like root['*'] are treated as literals, not wildcards.

>>> t1 = {"users": {"alice": {"name": "Alice", "pw": "s1"}, "bob": {"name": "Bob", "pw": "s2"}}}
>>> t2 = {"users": {"alice": {"name": "Alice", "pw": "x1"}, "bob": {"name": "Bob", "pw": "x2"}}}
>>> DeepDiff(t1, t2, exclude_paths=["root['users'][*]['pw']"])
{}

@seperman
Copy link
Copy Markdown
Member

Hi @akshat62 . The existing exclude_regex_paths should cover these. What is the benefit of supporting wildcard in exclude_paths and include_paths?

@akshat62
Copy link
Copy Markdown
Contributor Author

Hi @seperman,
exclude_regex_paths only supports exclusion. The wildcard support works in both exclude_paths and include_paths, giving users a single consistent syntax for both directions.

Users don't need to learn a separate parameter - wildcards work directly in the existing exclude_paths/include_paths they're already using. The implementation auto-separates exact paths from glob patterns internally.

The glob support targets the 80% of cases where users just want "this key at any depth" without needing to write regex.

@akshat62
Copy link
Copy Markdown
Contributor Author

Regex operates on the string representation of paths, so a pattern like r"b" would accidentally match root['pub'] or root['dba']. Glob matching works on parsed path segments, so root[*]['b'] only matches paths where 'b' is an actual key at that exact level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants