如何在 Android Studio logcat 中过滤多个词

How to filter multiple words in Android Studio logcat

我只想在 logcat 中看到几个单词。换句话说,只是一个给定的标签。我尝试启用 Regex 并输入 [Encoder|Decoder] 作为过滤器,但它不起作用。

您应该使用 分组 构造:

(Encoder|Decoder)

实际上,您可以使用

Encoder|Decoder

如果您使用 [Encoder|Decoder],将创建 字符 class 以匹配任何单个字符 Enc...|D...或r.

参见Character Classes or Character Sets

With a "character class", also called "character set", you can tell the regex engine to match only one out of several characters. Simply place the characters you want to match between square brackets. If you want to match an a or an e, use [ae].

另一个must-read肯定是Alternation with The Vertical Bar or Pipe Symbol:

If you want to search for the literal text cat or dog, separate both options with a vertical bar or pipe symbol: cat|dog. If you want more options, simply expand the list: cat|dog|mouse|fish.

当使用 (...) 时,您告诉正则表达式引擎对 characters/subpatterns 的 序列进行分组(对于捕获序列,子匹配存储在内存缓冲区中,并且您可以通过反向引用访问它们,并且使用 non-capturing (?:...) 您只对子模式进行分组):

By placing part of a regular expression inside round brackets or parentheses, you can group that part of the regular expression together. This allows you to apply a quantifier to the entire group or to restrict alternation to part of the regex.

您可以只使用 Encoder|Decoder 并且还必须选中 Regex CheckBox