I'm trying to pull multiple names from a listing of names on reddit, i.e.
"Title: /u/foo, /u/bar"
"Title - /u/foo and /u/bar"
"title-/u/foo, /u/bar and /u/foobar"
"Title /u/barfoo (/u/foo and /u/bar)"
and I'm having trouble matching an arbitrary number of names between 1 and maybe 100.
Edit: I don't think I made it clear that the example strings I gave are small snippets of the actual text I'm searching. I'm checking the bodies of posts in /r/KarmaCourt, like these:
http://www.reddit.com/r/KarmaCourt/comments/1ifz0u/ http://www.reddit.com/r/KarmaCourt/comments/28hv73/
The question is revolving around structuring a regex. I don't want to know how to search the sample strings I gave for the names.
I know that r'title.*/u/(\w{3:20})'
will match the last name in the line, r'title.*?/u/(\w{3:20})'
will match the first in the line, and that I could manually add some number of r'.*?/?u?/?(\w{3:20})?'
at the end of of the expression to match more names, but I can't help thinking that's a bad way of doing it.
Would it be better to take the matching string from r'title.*?(?=/u/\w{3:20})(.*)'
and pull all the matching r'/u/(\w{3:20})'
groups from that, or is there a way to do this all in one step that I'm fundamentally missing?
Note: this project is being done in python, but this is more of a fundamentals question.