Mikes3ds
Mikes3ds

Reputation: 600

REGEX Match [WildCard] but not [WildCard].[WildCard]

Using C# Regex

Example

Simple Input: [testA].[max] [testB]

Match: [testB]

Input: 5/[test1] [test2].[max] [test3]*2 [min]

Match:[test1] [test3] [min]

Definition

I want to match anything with like [Whatever] but not match [Whatever].[(min|max|mean|sum|median)]

Attempt

This works sort of it does not match [min] on its own.

(?!\[((\w|[.])+)\]\.\[(min|max|mean|sum|median)\])\[((?!min|max|mean|sum|median).+?)\]

Upvotes: 0

Views: 667

Answers (1)

Jonathan Twite
Jonathan Twite

Reputation: 952

How about

(?<!\.)\[[A-Za-z0-9]*\](?!\.\[.*\])
  • (?<!\.) - Negative lookbehind to prevent .[max] matching matching as well.
  • \[[A-Za-z0-9]*\] - Match [...], add other characters if necessary.
  • (?!\.\[.*\]) - Negative lookahead to ignore [...].[...].

Upvotes: 1

Related Questions