Python regex read file for specific pattern to look around | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

18th Feb 2020, 12:27 PM
arti bhasme
arti bhasme - avatar
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
18th Feb 2020, 12:53 PM
Taste
Taste - avatar