2

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:

^(stats\.gauges\..*\.(?:dur|hop|scz|led|bgi|shi|crk|sas)\.(?:p|s|q|u|d|x)\.)

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:

stats.gauges.gitswarm.dur.p.durgitswarm1.service.repos.eeps-merge_demo.users

But unfortunately someone entered some like:

stats.gauges.gitswarm.dur.p.durgitswarm1.dur.p.service.repos.eeps-merge_demo.users

So these match all the way to the second dur.p. skipping possible error on exact matches such as stats.gauges.gitswarm.durham.p.durgitswarm1.dur.p.service.repos.eeps-merge_demo.users; 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!

2
  • So why is stats.gauges.gitswarm.durham.p.durgitswarm1.dur.p.service.repos.eeps-merge_demo.users not following the standardized stats.gaugues.*.(exact OR match).(exact OR match).? In this case * matches gitswarm.durham.p.durgitswarm1. The problem is with your definition of *. Commented Nov 3, 2016 at 2:23
  • It needs to fail because 1) dur is the valid value, not durham and 2) dur.p. should should not be in the location it is even with the invalid value. I agree it is with the definition of *, I think that is what I'm having trouble placing into regex form. Commented Nov 3, 2016 at 2:27

1 Answer 1

2

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)\.)

Sign up to request clarification or add additional context in comments.

5 Comments

I don't think greedy or not matters here: OP is trying to spot negative cases
I tried that too :( ^(stats\.gauges\..*?\.(?:dur|hop|scz|led|bgi|shi|crk|sas)\.(?:p|s|q|u|d|x)\.) !Regular expression visualization Debuggex Demo
In that case can you elobrate you pattern because .* says match anything so you'll have to come up with something specific than .* Could you tell me what exactly could come in between stats.gauges. and dur.p. Would it always be one word?
Yes, exactly, it should only be one word. Just stats.gauges.{word}.dur|hop|etc.p|d|u. Sorry I didn't make that clearer early on.
I think you just helped the light bulb go off... I believe it should just be:^(stats\.gauges\.\w*\.(?:dur|hop|scz|led|bgi|shi|crk|sas)\.(?:p|s|q|u|d|x)\.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.