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

How to use anchored regular expressions? #1470

Closed
grobie opened this Issue Mar 8, 2016 · 4 comments

Comments

Projects
None yet
3 participants
@grobie
Copy link
Member

grobie commented Mar 8, 2016

@guanglinlv asked about the new anchored expressions in #1459:

node_cpu{instance=~"xx|yy",mode="user"} help me getting the point both xx and yy instance. it's very useful to make a comparing among different instance. how can i get that if regular expression is anchored ?

@grobie grobie added the question label Mar 8, 2016

@grobie

This comment has been minimized.

Copy link
Member Author

grobie commented Mar 8, 2016

In order to use anchored regular expressions, it's important to always match the full value from beginning to end.

# `xx` or `yy` are at the beginning of the instance label
node_cpu{instance=~"(xx|yy).*", mode="user"}

# `xx` or `yy` are at the end of a the instance label
node_cpu{instance=~".*(xx|yy)", mode="user"}

# `xx` or `yy` are somewhere in the instance label
node_cpu{instance=~".*(xx|yy).*", mode="user"}

It is recommended to be as specific as possible in order to not match other values.

@guanglinlv

This comment has been minimized.

Copy link

guanglinlv commented Mar 8, 2016

@grobie , aha, got it, regular expression must be match the full value. even if i want to match with substring. i will try it again. thanks a lot.

@beorn7

This comment has been minimized.

Copy link
Member

beorn7 commented Mar 8, 2016

Closing as the question is answered (thanks @grobie ). @guanglinlv please re-open if any issue remains.

@beorn7 beorn7 closed this Mar 8, 2016

@lock

This comment has been minimized.

Copy link

lock bot commented Mar 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Mar 24, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.