Regex Cheatsheet

To add any selection as a rule, you need to

  • highlight the selected text

  • right click and select LevelOps > Add selection to LevelOps Rule

If you want your selection to work as a simple string match, just click on "Escape special characters" in the pop-up.

This will ensure that the selected string will be match-ready

When you want to add stack traces or multi line matches as a triage rule, you need to ensure that you are not including any line numbers or log time stamps in your rule. Lets look at the lines below

Jul 08, 2020 2:58:27 PM INFO hudson.model.AsyncPeriodicWork lambda/var/lib/jenkins/workspace/master-sanity-pipeline@tmp/durable-8cbc9599/script.sh
Finished jobAnalytics. 1 ms
Jul 08, 2020 2:58:47 PM WARNING io.fabric8.kubernetes.client.dsl.internal.WatchConnectionManager onFailure
Jul 08, 2020 2:58:47 PM WARNING Exec Failure

When I want to create a rule, I do not want to include "Jul 08, 2020". So we will delete any time stamps from the selection

hudson.model.AsyncPeriodicWork lambda/var/lib/jenkins/workspace/master-sanity-pipeline@tmp/durable-8cbc9599/script.sh
Finished jobAnalytics. 1 ms
io.fabric8.kubernetes.client.dsl.internal.WatchConnectionManager onFailure
Exec Failure
```
Then click on the "Escape special characters", which will make it look like this

```
lambda\/var\/lib\/jenkins\/workspace\/master\-sanity\-pipeline@tmp\/durable\-8cbc9599\/script\.sh
Finished jobAnalytics\. 1 ms
io\.fabric8\.kubernetes\.client\.dsl\.internal\.WatchConnectionManager onFailure
Exec Failure

Now just append [\s\S]+ between the lines

lambda\/var\/lib\/jenkins\/workspace\/master\-sanity\-pipeline@tmp\/durable\-8cbc9599\/script\.sh
Finished jobAnalytics\. 1 ms[\s\S+]
io\.fabric8\.kubernetes\.client\.dsl\.internal\.WatchConnectionManager onFailure[\s\S+]
Exec Failure

Now, this is ready to run as a rule match for the stack trace

  • abc* matches a string that has ab followed by zero or more c

  • abc+ matches a string that has ab followed by one or more c

  • abc? matches a string that has ab followed by zero or one c

  • abc{2} matches a string that has ab followed by 2 c

  • abc{2,} matches a string that has ab followed by 2 or more c

  • abc{2,5} matches a string that has ab followed by 2 up to 5 c

  • a(bc)* matches a string that has a followed by zero or more copies of the sequence bc

  • a(bc){2,5} matches a string that has a followed by 2 up to 5 copies of the sequence bc

  • \d matches a single character that is a digit -> Try it!

  • \w matches a word character (alphanumeric character plus underscore) -> Try it!

  • \s matches a whitespace character (includes tabs and line breaks)

  • . matches any character

  • \D matches a single non-digit character

Last updated