Hugo Gresse
Hugo Gresse

Reputation: 17909

Android Logcat regex with app tag and custom TAG

I'm searching for a regex that I could se in Android Studio custom filter on logcat window. The window look like this : filter window

here is a log sample that I need to filter :

08-06 15:46:13.883  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ process
08-06 15:46:13.883  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ processUri
08-06 15:46:13.884  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ About to create doc from InputStream
08-06 15:46:13.886  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ Doc successfully created.
08-06 15:46:13.887  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ About to merge doc into main doc.
08-06 15:46:13.887  27841-12352/tv.me.sdkapptest D/me#XmlTools﹕ xmlDocumentToString
08-06 15:46:13.895  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ Merge successful.
08-06 15:46:13.895  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ Doc is a wrapper.
08-06 15:46:13.905  27841-12352/tv.me.sdkapptest D/me#BADTAG﹕ processUri
08-06 15:46:13.905  27841-12352/not.to.me D/me#BADTAG﹕ begin
08-06 15:46:13.905  27841-12352/tv.me.sdkapptest D/me#MainActivity : so

I want to keep line with tv.me.sdkapptest that not contain me#BADTAG or me#XmlTools

As a result, only the last line should match. I'm already using this : ^((?!(#BADTAG)|(#XmlTools)).)+$ but is does not remove not.to.me lines.

Upvotes: 1

Views: 431

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627469

You can use the following regex:

^(?!.*(?:me#BADTAG|me#XmlTools))

See demo

The regex means

  • ^ - Beginning of a line
  • (?!.*(?:me#BADTAG|me#XmlTools)) - a negative look-ahead that fails the match if the line has me#BADTAG or me#XmlTools in it

As you found out, to only display the log entries pertaining to some package, this package name must be added to the Package Name field in the Logcat Filter Dialog.

Upvotes: 1

Hugo Gresse
Hugo Gresse

Reputation: 17909

Actually the regex I posted in the question is the one. The things is that I was misreading the filter pannel which have the log tag, log message and package name. In my case, the package name is tv.me.app and the regex should remove on me#BADTAG or me#XmlTools in the tag log.

Here is the correct filter configuration enter image description here

Upvotes: 0

Related Questions