Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression to exclude set of Keywords

I want an expression that will fail when it encounters words such as "boon.ini" and "http". The goal would be to take this expression and be able to construct for any set of keywords.

like image 369
kae Avatar asked Sep 22 '08 19:09

kae


People also ask

How do you exclude a word in regex?

If you want to exclude a certain word/string in a search pattern, a good way to do this is regular expression assertion function. It is indispensable if you want to match something not followed by something else. ?= is positive lookahead and ?! is negative lookahead.

What is ?= * In regular expression?

. Your regex starts with (?= (ensure that you can see, but don't consume) followed by . * (zero or more of any character).

What does \b mean in regular expressions?

Simply put: \b allows you to perform a “whole words only” search using a regular expression in the form of \bword\b. A “word character” is a character that can be used to form words. All characters that are not “word characters” are “non-word characters”.


1 Answers

^(?:(?!boon\.ini|http).)*$\r?\n? 

(taken from RegexBuddy's library) will match any line that does not contain boon.ini and/or http. Is that what you wanted?

like image 191
Tim Pietzcker Avatar answered Oct 31 '22 22:10

Tim Pietzcker