I need a regex to match pieces starting with "[", containing "hi" and ending with "|]".
Input: [he] [picks] [him.|]
Match: [him.|]
Input: [it’s] [his|] [word.|]
Match: [his|]
I got started with \[\S*?\|\], but I don’t know how to add the condition that it only needs to match it when it contains ‘hi’.
>Solution :
You could say "Starts with [, doesn’t end with ], contains hi, doesn’t end with ], ends with |]":
\[[^\]]*hi[^\]]*\|\]
\[ Starts with [
[^\]]* Contains no ]
hi Contains hi
[^\]]* Contains no ]
\|\] Ends with |]
Examples: