index.js
function getSubredditName(url) {
  try {
    // This will throw a `TypeError: Cannot read property 'Symbol(Symbol.iterator)' of null` if the RegExp fails.
    const [input, name] = new RegExp('^https?://(?:www.)?reddit.com/r/(.*?)/?$').exec(url);
    return name;
  } catch (err) {
    return null;
  }
}
function getSubredditName(url) {
  try {
    // This will throw a `TypeError: Cannot read property 'Symbol(Symbol.iterator)' of null` if the RegExp fails.
    const [input, name] = new RegExp('^https?://(?:www.)?reddit.com/r/(.*?)/?$').exec(url);
    return name;
  } catch (err) {
    return null;
  }
}
function getSubredditName ( url ) { try { // This will throw a `TypeError: Cannot read property 'Symbol(Symbol.iterator)' of null` if the RegExp fails. const [ input , name ] = new RegExp ( '^https?://(?:www.)?reddit.com/r/(.*?)/?$' ) . exec ( url ) ; return name ; } catch ( err ) { return null ; } }
Extracts a subreddit name from a URL using sketchy RegExp.

@param  {String} url A fully qualified URL.
@return {String}     The name of a subreddit. For example: "knitting"
Extracts a subreddit name from a URL using sketchy RegExp .