regex - Regular expression to remove lines containing word with exceptions -


i using regex in powergrep, (this regex search strings lab rad tran)

.*((lab)|(rad)|(tran)).*\r\n 

to search , remove lines in plain text contains strings or part of string , works great.

now need more. want keep word laber, remove every other string containing lab, such labor, lab1, alab, alaba, etc. there way "protect" string laber , remove every other string containing lab? tried alter above regex using * includes word laber need keep. solution?

you can add exclusions regex in form means of look-ahead:

(?m)^.*(lab(?!(?:er|ov)\b)|rad|tran).*$ 

the (?!(?:er|ov)\b) lookahead check if sequence lab not followed er or ov , word boundary.

i adding alternation look-ahead because ask "protect" laber , labov.

also, since looking whole lines, can make use of multiline mode (?m) , ^/$ anchors.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -