devlopp
devlopp

Reputation: 437

Could not find the right regex pattern

I want to write a regular expression to match every word which :

I wrote this regular expression, but it does not work as expected

(?!TEMP_)+(?!TMP_)+(\w)+LME999+(\w)+((?!.flag)(?!_TEMP))

Here are some valid string: StringLME999String

Upvotes: 2

Views: 91

Answers (1)

anubhava
anubhava

Reputation: 785761

You can use this regex:

^(?!TE?MP_).*?LME999.*$(?<!\.flag|_TEMP)

RegEx Demo

RegEx Breakup:

^                   # line start
(?!TE?MP_)          # negative lookahead to assert failure if starts with TMP_ or TEMP_
.*?                 # match 0 or more of any char (lazy)
LME999              # match LME99
.*                  # match 0 or more of any char 
$                   # line end
(?<!\.flag|_TEMP)   # negative lookbehind to assert failure if ends with .flag or _TEMP

Upvotes: 4

Related Questions