I’m making a reusable piece of code. One can specify the regular expression for capturing the api_key and signature groups, like in the following Authorization header:
AWS 44CF9590006BF252F707:jZNOcbfWmD/A/f3hSvVzXZjM2HU=
The regular expression would be:
^AWS (?<api_key>.+):(?<signature>.+)$
Of course AWS and the order of the key/signature pair may change (that’s why I’m using a regular expression). But there should be always an api_key capturing group and a signature capturing group.
How can I check if these groups are present, using another regular expression?
EDIT: based on the answers it seems that I was not good at all at explaining the problem.
The user (of this code) is going to provider the regex (like the one above). I need only to check that the given regex as (at least) two capturing grops (api_key and signature). I’ll then use the regex provided to test against Authorization header.
But how do you know that your new regex tests your regex properly? You might need 20-30 levels of regexes :). How about you just try something simple like:
This is I guess more fool proof: