Regular Expression Examples

These examples show how to construct regular expressions to achieve different results.

Matching Non-Adjacent URL Segments

A typical use of regular expressions in the Splunk AppDynamics configuration is for business transaction custom match rules in which the expression is matched to a requested URI. In this context, it's common for an application's URI pattern to put information that would be useful for business transaction identification in different segments of the URI.

For example, given an example URL of http://retailstore.example.com/store/jump/category/shoes/departments/view-all/cat630006p, a business transaction might need to match on /store/jump and all to group user requests to view all of an available category.

A regular expression to match this case could be:
/store/jump.*\b?all\b

Matching Any Digit

Say you want to ignore numbers contained within a pattern. For example, consider the following URL examples:

  • /group/1/session/

  • /group/1/session/

  • /group/31/session/

  • /group/2/session/

Examples of matching regular expressions would be:

  • ^/group/\d*/session/?$
  • session
  • /\d*/session/?$

Requiring a Digit

To group URLs that contain letters then numbers into one business transaction, such as the following:

  • /aaa123.aspx
  • /b1.aspx

You could use an expression such as the following:

/[a-z]+?[0-9]+?

Not matched would be a URL that does not have digits after the letters, for example: /z.aspx

Handling Letter Casing

Regular expression matching is performed in a case-sensitive manner. To match any case letters, you can use something similar to the following:

/[a-zA-Z]+?[0-9]+?

Or match in a case-insensitive manner using theimodifier. For example:

(?i)\w*cart\w*

Would match addToCart addTocart

Backend Discovery Rules

For an example of a JDBC backend regular expression, see the section JDBC with complex URLs in Example JDBC Backend Configuration.

Note: You can find resources for testing your own regular expressions at http://www.regexplanet.com/advanced/java/index.html. There you can find regular expression test pages for many language engines, including Java, JS, .NET, PHP and more.