90

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

AndriuZ
  • 648
  • 6
  • 26
kraftwer1
  • 5,253
  • 10
  • 36
  • 54

4 Answers4

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)/
Black
  • 18,150
  • 39
  • 158
  • 271
kraftwer1
  • 5,253
  • 10
  • 36
  • 54
  • Ah, just found this is/was [a bug](https://groups.google.com/forum/#!topic/google-chrome-developer-tools/cdJCK5tVqW8) – Remco Oct 22 '16 at 19:08
  • 4
    I wish I could give you 20 updoots. – Dave Land Dec 16 '16 at 02:23
  • 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 04 '17 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, https://developers.google.com/web/tools/chrome-devtools/console/#filtering_the_console_output Do you even see the selectors for All, Errors, Warnings and all? – Arjan Feb 06 '17 at 08: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 07 '17 at 01:14
  • @Dave, quite funny as I came to this question to figure out how to use `^` in the regular expressions (for the start-of-line; seems to have no effect, or I don't know what exactly it's looking in). And then I read your first comment. Good to know the current implementation is apparently not a proper regex, which is better than me losing my mind ;-) – Arjan Feb 07 '17 at 07:32
  • It's coming, it would appear… They seem to fiddle around with the regex searching in the console & networks tabs every couple of versions. I hope that the version currently in Canary (currently on 58) is reliable and stable. – Dave Land Feb 07 '17 at 16:02
  • 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 '19 at 06: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/
Venryx
  • 15,624
  • 10
  • 70
  • 96
  • 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 09 '20 at 01:11
15

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.

Artif3x
  • 4,391
  • 1
  • 28
  • 24
-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?

aairey
  • 310
  • 1
  • 3
  • 13