How to filter multiple words in Android Studio logcat

Pitel picture Pitel · Jan 13, 2016 · Viewed 14.3k times · Source

I want to see just a couple of words in logcat. In other words, just a given tags. I tried to enable Regex and type [Encoder|Decoder] as filter, but it doesn't work.

Answer

Wiktor Stribiżew picture Wiktor Stribiżew · Jan 13, 2016

You should use a grouping construct:

(Encoder|Decoder)

Actually, you can just use

Encoder|Decoder

If you use [Encoder|Decoder], the character class is created that matches any single character E, n, c... |, D... or r.

See 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].

Another must-read is certainly 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.

When using (...) you tell the regex engine to group sequences of characters/subpatterns (with capturing ones, the submatches are stored in the memory buffer and you can access them via backreferences, and with non-capturing (?:...) you only group the subpatterns):

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.