简体   繁体   中英

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).+?)\]

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 [...].[...] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM