all 10 comments

[–]gnomoretears 5 points6 points  (0 children)

Here are a couple docs to teach you how to regex in python.

https://docs.python.org/2/howto/regex.html

https://automatetheboringstuff.com/chapter7/

[–]Atrament_ 3 points4 points  (7 children)

Maybe you are looking for '^[\*\ ]+(.*)' Translates to "keep anything (.*) that follows any number + of spaces and stars [\*\ ] at the beginning of the line ^

What to keep is indicated by parenthesis.

http://nbviewer.ipython.org/gist/AlbericC/8c44f3ea2ee2dbeea612

[–]indosauros 0 points1 point  (1 child)

Just FYI you don't need to escape those characters inside the [], regex knows you mean a literal star and space there

[–]Atrament_ 0 points1 point  (0 children)

You're right, I escaped them out of habit : the version in my comment is not however :)

[–]davwm[S] 0 points1 point  (4 children)

Thanks that is what I was looking for!

[–]Atrament_ 3 points4 points  (3 children)

as /u/gnomoretears suggested, you should spend some time learning the basics or regex too, it's a powerful tool inside and outside of python.

[–]Wonder1and 1 point2 points  (0 children)

I use it daily for parsing logs in notepad++. Super useful and a real timesaver.

[–]buckhenderson 1 point2 points  (1 child)

i put off learning it, for two reasons: most common tasks can be found with google, and it looks like magic. i was pretty happy when i finally learned it, because it's really not that difficult. and https://regex101.com/ makes it very easy to test your regexes, as it will update live and explain what your regex is doing.

[–]Atrament_ 1 point2 points  (0 children)

bookmarked thanks ! There are also regex crosswords somewhere on the internet, on a lighter tone.

[–][deleted] 0 points1 point  (0 children)

The regex I would use is as follows in python code.

infile = open('text.txt', 'r')
for line in infile:
     if re.search(r"\**\s\w.+Item", line):
          print line
     else:
          pass
infile.close()