0
Python regex read file for specific pattern to look around
I want to understand the regex pattern for reading all lines from log file that contains #####anys string##### like this
1 Answer
0
(?<=#+)[\w\s]+(?=#+)
[\w\s]+ is simply "one or more alpanumeric and whitespace"
(?<=#+) means "if thereis one or more # behind"
(?=#+) means "if thereis one or more # ahead"
symbol used here
\w alphanumeric and _
\s whitespace
[] match any character inside
+ one or more
?<= positive lookbehind, see if there's matching pattern behind
?= positive lookahead, see if there's matching pattern ahead