Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regexmatch certain characters and ends with

I need a regex to match pieces starting with "[", containing "hi" and ending with "|]".

Input: [he] [picks] [him.|]

Match: [him.|]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading