Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add regex validation function #29

Merged

Conversation

WhileLoop
Copy link
Contributor

add a regex validation helper function and a regex example

@WhileLoop
Copy link
Contributor Author

Is it possible to apply functions to anything other than response body?

@benhowes
Copy link
Member

@WhileLoop Thanks, this is a great addition!

I suspect that you might be able to get away without the group matching aspect of this for the most part? Unless I'm missing a case where you need to be able to match the groups individually?

@WhileLoop
Copy link
Contributor Author

I made the group matching useful by allowing them to be saved and reused.

@michaelboulton michaelboulton mentioned this pull request Feb 20, 2018
@benhowes
Copy link
Member

@WhileLoop Sorry for the delay in getting back to you on this. I've been thinking about it a bit and wondering if a nicer way of doing this could be to use "named groups" in regexes. This could mean that we automatically save the contents of the named groups to the name if provided. Un-named groups could be dropped. The re module provides this which would make it pretty easy to implement too.

What do you think?

'full_match': full_match,
'groups': groups
})
"regex": Box(match.groupdict())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon they might be okay without being keyed on the dict, i.e. they could just be top level variables? so you can just return the Box(match.groupdict())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the pattern of the other helpers. Also returning the matches as top level variables increases chance some other existing variable being overwritten inadvertently.

@benhowes
Copy link
Member

I think this is looking good @WhileLoop! I think @michaelboulton should have a look too and possibly a few tests of the functionality can be added.

@michaelboulton
Copy link
Member

The only (minor) issue with this is that it forces people to use named match groups, but I actually like the named groups

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.

4 participants