91

Could anyone provide an example of a regex filter for the Google Chrome Developer toolbar?

I especially need exclusion. I've tried many regexes, but somehow they don't seem to work:

enter image description here

1
  • 20
    Would kill one IE user for an answer on this one
    – Israel
    May 27, 2015 at 11:30

4 Answers 4

111

It turned out that Google Chrome actually didn't support this until early 2015, see Google Code issue. With newer versions it works great, for example excluding everything that contains banners:

/^(?!.*?banners)/
7
  • Ah, just found this is/was a bug
    – Remco
    Oct 22, 2016 at 19:08
  • 1
    Recently, the Regex checkbox (and the ability to filter by regular expressions) seems to have vanished. Is anyone else seeing that?
    – Dave Land
    Feb 4, 2017 at 19:17
  • @Dave, I just upgraded from 55.0.2883.87 m to 56.0.2924.87 (Windows 7) and it's still there. Note that, as always, you first need to enable filtering (hit the filter icon next to "preserve log") to see the filter toolbar, developers.google.com/web/tools/chrome-devtools/console/… Do you even see the selectors for All, Errors, Warnings and all?
    – Arjan
    Feb 6, 2017 at 8:28
  • 5
    @Arjan, Thanks. I'm on Version 57.0.2987.21 beta (64-bit). It is missing in that build, and is apparently being replaced in 58 by a "proper" implementation using the /regex/ format. Grab a copy of Canary to see it in action, if you like.
    – Dave Land
    Feb 7, 2017 at 1:14
  • 3
    could you explain why this regex ^(?!.*?banners) doesn't work without ^ at the beginning? (I understand that ^ is start of expression in regex)
    – vitm
    Feb 11, 2019 at 6:55
37

It's possible -- at least in Chrome 58 Dev. You just need to wrap your regex with forward-slashes: /my-regex-string/

For example, this is one I'm currently using: /^(.(?!fallback font))+$/

It successfully filters out any messages that contain the substring "fallback font".

EDIT

Something else to note is that if you want to use the ^ (caret) symbol to search from the start of the log message, you have to first match the "fileName.js?someUrlParam:lineNumber " part of the string.

That is to say, the regex is matching against not just the log message, but also the stack-entry for the line which made the log.

So this is the regex I use to match all log messages where the actual message starts with "Dog":

/^.+?:[0-9]+ Dog/
1
  • 4
    Btw: None of the answers work reliably for me anymore, in Chrome 79 -- including the exact patterns listed. Since they worked before, I'll need to do more testing to see what's causing some to fail.
    – Venryx
    Jan 9, 2020 at 1:11
16

The negative or exclusion case is much easier to write and think about when using the DevTool's native syntax. To provide the exclusion logic you need, simply use this:

-/app/ -/some\sother\sregex/

The "-" prior to the regex makes the result negative.

-4

Your expression should not contain the forward slashes and /s, these are not needed for crafting a filter.

I believe your regex should finally read:

!(appl)

Depending on what exactly you want to filter. The regex above will filter out all lines without the string "appl" in them.

edit: apparently exclusion is not supported?

1
  • Hmm you are right, regexes seem to work okay but exclusion does not :/
    – aairey
    Oct 2, 2014 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.