43

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.

Pitel
  • 5,334
  • 7
  • 45
  • 72

3 Answers3

72

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.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 6
    I'll just add.. TAG1|TAG2 without spaces. – wsgeorge Apr 29 '16 at 11:29
  • @wsgeorge: I do not understand what you mean. Look, I already wrote *Actually, you can just use `Encoder|Decoder`* - isn't it the same? Also, if you really have a literal `TAG` followed with any number, no alternation is necessary, use `TAG\d+` :) – Wiktor Stribiżew Apr 29 '16 at 11:31
  • 2
    I'm in the habit of adding spaces between operators, so I literally used "TAG1 | TAG2" in AS and found it didn't work. I just thought others should know to avoid this little gotcha. – wsgeorge Apr 29 '16 at 11:35
  • Then, you should think of falling into another habit: using `/x` freespace/VERBOSE/IgnoreWhiteSpace modifier. `/ TAG1 | TAG2 /x` will match either `TAG1` or `TAG2` with no spaces. This option is not present in JavaScript, but is present in many NFA regexes. – Wiktor Stribiżew Apr 29 '16 at 11:37
  • 1
    you are right, i am deleting the comment – thahgr Nov 01 '21 at 11:56
  • In 2023, it appears that spaces around `|` are needed: https://developer.android.com/studio/debug/logcat#logical-operators For example, when I want to see everything for my Flutter app and Firebase logs, I use: `flutter | Fire` – Ross Llewallyn Feb 17 '23 at 16:35
  • 1
    @RossLlewallyn You are confusing query language operators and regex alternation "operator". – Wiktor Stribiżew Feb 17 '23 at 17:29
0

you can just use Encoder|Decoder and must check Regex CheckBox too

Farid Savad
  • 163
  • 1
  • 11
0

For the new logcat you need spaces between pipes, eg.

package:mine AuthenticationHelper | identify | migration
Tom
  • 6,946
  • 2
  • 47
  • 63