Filter by regex example

微笑、不失礼 提交于 2019-11-27 10:40:28

问题


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:


回答1:


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)/



回答2:


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/



回答3:


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?



来源:https://stackoverflow.com/questions/26158916/filter-by-regex-example

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