So i'm trying to create a Regex find and replace function to take the Source Medium Path dimension from Google Analytics, and return a value that matches up with the Source Medium dimension. For example, when I'm looking at the total conversions for Source Medium Path, I get values like:
- google / cpc > google / organic
- google / cpc > google / organic > (direct) / (none)
- google / organic
- (none) > (none) > (none) > google / organic > (direct) / (none) > (direct) / (none)
- (direct) / (none)
This isn't the prettiest format and will be difficult for our clients to understand in their reporting, so I'd like to replace these values with their equivalent Source / Medium dimension:
- google / organic
- google / organic
- google / organic
- google / organic
- (direct) / (none)
The Regex find/replace function I've tried so far looks like it works for everything except the #4, where the Path ends with multiple iterations of 'direct / (none)', and mistakenly pulls in '(direct) / (none)' instead of 'google / organic'.
Essentially, this should find the last Source / Medium in the Path (ie 'google / organic' in 1 and 3), unless the last Group is '(direct) / (none)' (like in 2/4/5), in which case it should use the last Group that isn't '(direct) / (none)', and replace with the Source / Medium, unless the Path only contains one or more iterations of '(direct) / (none)', in which case it should replace with the value '(direct) / (none).
Any help in how I can fix this would be much appreciated! See below for what I have so far:
find: ^(.* \/ .* > )*(?'foo'.* \/ .*) > (direct \/ \(none\))+$|^(.* \/ .* > )(?'var'.* \/ .*)$
replace with: ${foo}${var}
^(?:(?:\(none\) > )+|(?:\w+ \/ \w+ > ))?(\w+ \/ \w+)(?!\S).*and replace with group 1 See regex101.com/r/L6MnWN/1 - The fourth bird^(?:(?:\(none\) > )+|(?:\w+ \/ \w+ > ))?(\w+ \/ \w+|\(direct\) \/ \(none\))(?!\S).*regex101.com/r/NQrhXr/1 - The fourth bird