Regex – Looking for a string with regex and delete the whole line

regextextpad

I am trying to find in Textpad a character with regex (for example "#") and if it is found the whole line should be deleted. The # is not at the beginnen of the line nor at the end but somewehre in between and not connected to another word, number or charakter – it stands alone with a whitespace left and right, but of course the rest of the line contains words and numbers.

Example:

My first line
My second line with # hash
My third line# with hash

Result:

My first line
My third line# with hash

How could I accomplish that?

Best Answer

Let's break it down:

^     # Start of line
.*    # any number of characters (except newline)
[ \t] # whitespace (tab or space)
\#    # hashmark
[ \t] # whitespace (tab or space)
.*    # any number of characters (except newline)

or, in a single line: ^.*[ \t]#[ \t].*

Related Topic