Home > Software engineering >  Reg expression to exclude string with % char in it
Reg expression to exclude string with % char in it

Time:08-19

I want to match all the instances of filter[ ... ] but excluding the ones that have a % char in them:

filter[first_name%0]=Tim&filter[first_name]=Tom&filter[first_name]=Bob

The /filter\[.*?\]/i gets all of the instances but how do I exclude the one with % in it?

CodePudding user response:

You can use

filter\[[^\][%]*]

See the regex demo

Details

  • filter\[ - a filter[ string
  • [^\][%]* - zero or more (*) chars that are not equal to ], [ and %
  • ] - a literal ] char.
  • Related