I'm using PRAW with Python and I want to be able to:

Go through the "new" posts on a subreddit Detect if there is a link to a subreddit in the posts selftext If there is a subreddit linked, get that subreddit as a PRAW object that will be used later.

I can do step 1, but finding if there is a subreddit linked and then getting that subreddit is the hard part for me. Here's what I've got so far:

#! python3 # Reply with subreddit info from subreddit in text body import praw, time # Bot login details USERNAME = "AutoMobBot"; PASSWORD = "<redacted>"; UA = "[Subreddit Info Provider (Update 0) by /u/MatthewMob]"; r = praw.Reddit(UA); r.login(USERNAME, PASSWORD, disable_warning=True); submissions = r.get_subreddit("matthewmob_csstesting").get_new(limit=10); for submission in submissions: for word in submission.selftext.lower().split(): if word.startswith("/r/"): print("Found subreddit in:", submission.title); print(submission.selftext_html); print("Done..."); input();

This will just get the submissions, split the words in the selftext, and print out something if one of the split words starts with /r/ , obviously this wouldn't work all the time if the user, for example, only linked the subreddit as r/askreddit or www.reddit.com/r/askreddit . And even then, if they linked /r/askreddit/top (with something on the end) how would I be able to get that subreddit as a PRAW object? I've been trying to find some kind of regex code to help me do this but have not found it.

My main question is what is the best way to do get the subreddit from the link in the users selftext, and how do I do that?

If you need any more clarification I am happy to provide more information.