NoctemX NoctemX - 2 months ago 13
Python Question

Need a little regex help in python

I have a long list of namespaces coming from a graphite instance and am trying to run some validation and filter out the namespaces that have not been entered using the correct format.

I can do ok with regex usually, but this one is hurting me and was hoping someone could help.

There is some basic validation that needs to be done and I've come this far:


The goal is to filter and match on the ones following the standardized
stats.gaugues.*.(exact OR match).(exact OR match).

This works ok for something like:


But unfortunately someone entered some like:


So these match all the way to the second
skipping possible error on exact matches such as
; which I don't want.

I feel like this is something pretty simple, but can't seem to grasp it so far.

Any help would be very much appreciated.

Thank you!


This should work. Basically you need to make your .* non greedy ^(stats\.gauges\..*?\.(?:dur|hop|scz|led|bgi|shi|crk|sas)\.(?:p|s|q|u|d|x)\.)