Required regex to match word example - "active users"

Viewed 66

Guys could you please help on creating a Regex for below Scenario.

I'm trying to create regex to match file name active users in wildcard.

Tried the basic one but doesn't work (?i)^active users$

example:

  1. Regex should match the word(active users) with case insensitive
  • AcTiVE Users
  • active users
  • ACTIVE USERS
  1. Regex should also match the word(active users) even though character present in prefix and suffix
  • Active users_test
  • Test_ACTIVE USERS
1 Answers

You can exclude matching word characters without the underscore at the left and at the right instead of using the anchors.

(?i)(?<![^\W_])active users(?![^\W_])

Regex demo

Related