Peter W
Peter W

Reputation: 1080

Is it possible to filter Chrome console log using a negated text?

Given console log output such as:

...
app.js:4408 update w/ model.location: Discovering
app.js:4408 update w/ action: Animate 911583 { width = 320, height = 480 }
app.js:4408 update w/ model.location: Discovering
app.js:4408 update w/ action: Animate 911609 { width = 320, height = 480 }
app.js:4922 some other log message
app.js:1923 yet another thing on the console
...

Is it possible to get Chrome to remove all lines that include the word "Animate"?

I've tried using a negative lookahead like: .*(?!Animate).* (see also: How to negate specific word in regex?) in Chrome, with no luck.

The regex has been tested at regexpal:

Regex tested at regexpal.com

But it has no effect in Chrome:

Chrome dev tools showing no effect from regex filtering

Being able to just type "!Animate" or "Animate" [x] negate filter would be great. Is that possible, or can anyone get a negate regex to work in this situation?

Thanks.

Upvotes: 21

Views: 5138

Answers (3)

user1990009
user1990009

Reputation: 965

Since chrome 62 you can use negative filters in dev tools.

In the console filter box enter:

-<textToFilter> 

I.e: To remove entries with text "Animate" just type:

-Animate

More info:

https://developers.google.com/web/updates/2017/08/devtools-release-notes#negative-filters

Upvotes: 47

Gideon Pyzer
Gideon Pyzer

Reputation: 23958

You can use this to filter out any result that contains the Animate string at any point in main string:

^((?!Animate).)*$

Explanation:

  • ^ - Start of string
  • (?!Animate) - Negative lookahead (at this cursor, do not match the next bit, without capturing)
  • . - Match any character (except line breaks)
  • ()* - 0 or more of the preceding group
  • $ - End of string

Side Note:

Negative lookahead is currently broken in the Network panel, but fine in the Console panel. I discovered the issue when I was answering this question recently. I pushed a fix, awaiting review.

Upvotes: 2

Nigrimmist
Nigrimmist

Reputation: 12338

You need to use :

 ^(?!.*?Animate) 

Upvotes: 1

Related Questions