deepdiff icon indicating copy to clipboard operation
deepdiff copied to clipboard

feature request: comparing dict with strings to dict with regex values

Open Iftahh opened this issue 9 years ago • 3 comments

I'd like to compare a dictionary where some of the expected values are regex to be matched to matching string values.

eg. something along:

    actual = { 'a': 'abcd', 'b': 'test' }
    # expecting 'b' to be exactly 'test' and expecting 'a' to be a four letter lowercase word
    expected = { 'a': re.compile('[a-z]{4}'),   'b': 'test' }   
    print DeepDiff(actual, expected,  regexMatching=True)    # prints {}

I figure it will be very easy to implement, a small extension of type_changes from string to regex.

Iftahh avatar Nov 22 '16 10:11 Iftahh

Hi @Iftahh This is going to be tricky especially with ignore_order=True since we create the hash of all objects and won't know what we will be comparing that object to in the future when doing diffing. It is easy to implement it when ignore_order=False though. Sorry it took me such a long time to respond. Are you interested in making a PR for it?

seperman avatar Mar 24 '19 08:03 seperman

+1 amazing feature to have Let's use regex based comparison too

"root[0]['Workspace']": {'new_value': '/auto/san1-99-box/prod/facebook/ncs5500/ws',
                                             'old_value': '\\S+'}}}

sathishsms avatar Apr 04 '21 04:04 sathishsms

+1 using regex for values comparison would be great. I work with network configuration and want to verify specific parts of the configuration which is deeply nested. Regexes are a must, for reasons that i cannot make obvious in a few lines.

nkalyvas avatar Oct 04 '21 19:10 nkalyvas