Showing results for 
Show  only  | Search instead for 
Did you mean: 

RegEx - Match string that doesn't contain set of words

Dynatrace Helper
Dynatrace Helper


I'm currently in the process of creating a Business Transaction that filters on a particular JS ADK value. The JavaScript ADK String Value Measure only has options for the key and a transformation regex. To provide a simple explanation of what I am trying to do, let's say I'm only looking for user actions with JS variable key1 that do not equal red, green, or blue.

For the 'Key for ADK String value', I input key1

For the 'Transformation Regex', I used ^(?!.*(red|green|blue)).*$

The regex does not seem to work correctly in the tool, but testing the regex on a site like works great. Any thoughts would be greatly appreciated!




Dynatrace Leader
Dynatrace Leader

I remember I did some negative look ahead stuff with the extended email plugin and what worked for me there was doing something like ^(?!.*(red)|.*(green)|.*(blue)).*$

I don't remember if this was specific to what I was searching for but I do remember stuff that worked in testers not working in the plugin so maybe try that. It could be completely off from what your issue is but worth a shot.

If you want you can shoot me an email with a session I can poke around in too.


Good Morning James,

Your regex worked great, thanks for the help!



Now if only we knew why...

Haha, Both regex are pretty similar!

In my opinion, the reason why James' regex works is because of an idiosyncrasy in our "transformation" code, and could be considered a bug (but we won't, because it's the only way you can get your use case to work). It can only work as a filter, but not as a splitting.

When we "transform" a string with a regex, we collect the groups that match into a combined transformed string.

In the cases that interest you (strings not containing either red, green or blue), the three groups in James' regex evaluate to "null" and we return the string

null null null

This is clearly not an empty string, so we return it as a splitting (and you would be unhappy with the splitting if you wanted the original string as a value), but more importantly, we consider the value to be relevant for the filter (i.e. we don't filter it out).

The only group in Kodai's original regex also evaluates to null, but in the special case of only one group we don't do any pasting and so on and actually return a null object as the string, which gets replaced by an empty string, which then results not in an empty splitting but in no splitting at all, which tells the filter to not consider the value at all.

So, in short, the reason why it works at all is the difference of 3 groups to 1 group. And don't use this when you're actually interested in the splitting itself.