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

你离开我真会死。 提交于 2020-06-27 07:38:06

问题


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:

But it has no effect in Chrome:

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.


回答1:


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.




回答2:


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




回答3:


You need to use :

 ^(?!.*?Animate) 


来源:https://stackoverflow.com/questions/38823920/is-it-possible-to-filter-chrome-console-log-using-a-negated-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!