question: public static String formatRedditUrl ( String url ) { url = url . replaceFirst ( "(?i)^(https?://)?(www\\.)?((ssl|pay|amp)\\.)?" , "" ) ; if ( url . matches ( "(?i)[a-z0-9-_]+\\.reddit\\.com.*" ) ) { String subdomain = url . split ( "\\." , 2 ) [ 0 ] ; String domainRegex = "(?i)" + subdomain + "\\.reddit\\.com" ; if ( subdomain . equalsIgnoreCase ( "np" ) ) { url = url . replaceFirst ( domainRegex , "reddit.com" ) ; url = "np" + url ; } else if ( subdomain . matches ( "beta|blog|code|mod|out|store" ) ) { return "" ; } else if ( subdomain . matches ( "(?i)([_a-z0-9]{2}-)?[_a-z0-9]{1,2}" ) ) { url = url . replaceFirst ( domainRegex , "reddit.com" ) ; } else { url = url . replaceFirst ( domainRegex , "reddit.com/r/" + subdomain ) ; } } if ( url . startsWith ( "/" ) ) url = "reddit.com" + url ; if ( url . endsWith ( "/" ) ) url = url . substring ( 0 , url . length ( ) - 1 ) ; if ( url . matches ( "(?i)[^/]++/(?>wiki|help)(?>$|/.*)" ) ) { url = url . replaceFirst ( "(?i)/(?>wiki|help)" , "/r/reddit.com/wiki" ) ; } return url ; }
target:  Takes an reddit.com url and formats it for easier use