AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
3.4K members online now
3.4K members online now
Ask questions about filter set-up and issues with using filters in Google Analytics reports
 
Guide Me
star_border
Reply

Regex By Character / Number Length

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I am looking to set up a filter or segment that detects if a dimension is only 7 characters in length. Characters include numbers and letters. 

 

For example, I want to filter / segment transaction ID number that only contain 7 characters.

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Steve P
June 2017

Regex By Character / Number Length

[ Edited ]
Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Could you do something like this?

Transaction ID REGEX ^......$

 

Each of the 7 dots represents a wild card (any character).

The means the start of the string, $ is the end.

So the filter should catch only strings with 7 characters from the start to the end.

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Steve P
June 2017

Regex By Character / Number Length

[ Edited ]
Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Could you do something like this?

Transaction ID REGEX ^......$

 

Each of the 7 dots represents a wild card (any character).

The means the start of the string, $ is the end.

So the filter should catch only strings with 7 characters from the start to the end.

Regex By Character / Number Length

Top Contributor
# 3
Top Contributor

If you are looking for a string that will always be 7 characters. the following should work

[A-Za-z0-9]{7}

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Re: Regex By Character / Number Length

Explorer ✭ ✭ ☆
# 4
Explorer ✭ ✭ ☆

Combining Brent & Bronwyn answers:

  • Brent is almost right, but the proposed regex will match ABC-123 (with a dash, and still 7 characters)
  • Bronwyn is also almost right but she forgot the ^ and $ that Brent mentioned, so her regex would match ABC124ABC124ABC123 (longer than 7)

Make sure to use this instead: ^[A-Za-z0-9]{7}$

 

Regex By Character / Number Length

Top Contributor
# 5
Top Contributor

Thanks @Stéphane Hamel :-))

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here