Regular Expressions 101

Community Patterns

Find Reddit Threads

10

Regular Expression
Python

r"
(^https?://)?(\w+)?\.?(reddit\.com/|redd\.it/)(r/\w+/)?(comments/)?(\w+)
"
gm

Description

Simply searches for the thread-id in any kind of valid reddit-URL.

Submitted by Mio - 9 years ago