regex - python - find text between two $ and get them into a list -
i have text file -
$ abc defghjik here not $ not here go there $ ....
i want extract text between 2 $ signs , put text list or dict. how can in python reading file?
i tried regex gives me alternate values of text file:
f1 = open('some.txt','r') lines = f1.read() x = re.findall(r'$(.*?)$', lines, re.dotall)
i want output below - ['abc', 'defghjik', 'am here', 'not now'] ['you', 'are not', 'here go there']
sorry new python , trying learn, appreciated! thanks!
in regular expressions $
character of special meaning , needs escaped match literal character. match multiple parts use lookahead (?=...)
assertion assert matching literal $
character.
>>> x = re.findall(r'(?s)\$\s*(.*?)(?=\$)', lines) >>> [i.splitlines() in x] [['abc', 'defghjik', 'am here', 'not now'], ['you', 'are not', 'here go there']]
Comments
Post a Comment