0

I'd like to show logs that contain MainActivity but don't contain ActivityManager, so that this match is excluded:

I/ActivityManager: Start proc 2666:com.example.app/u0000 for activity {com.example.app/com.example.app.MainActivity}

I tried as suggested here:

(?=(MainActivity))(?!(ActivityManager))

But it didn't work.

activity
  • 2,653
  • 3
  • 20
  • 44

1 Answers1

1

You could make use of a single negative l lookaheadand, use an anchor ^ at the start of the string.

^(?!.*\bActivityManager\b).*\bMainActivity\b.*

That will match

  • ^ Start of string
  • (?!.*\bActivityManager\b) Negative lookahead, assert that ActivityManager is not present
  • .*\bMainActivity\b.* Match the whole line with bMainActivity

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70