Get Twitter username from twitter url - Java Network

Java examples for Network:URL

Description

Get Twitter username from twitter url

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String url = "java2s.com";
        System.out.println(twitterUsernameFromUrl(url));
    }/*from  ww  w.  ja v  a2  s  . c om*/

    /**
     * Get Twitter username from twitter url
     *
     * @param String url
     * @return String url
     */
    public static String twitterUsernameFromUrl(String url) {
        if (null == url) {
            return null;
        }
        String re = "(http)?s?(://)?(www.)?twitter.com/(#!/)?";
        url = url.replaceAll(re, "");
        return url;
    }
}

Related Tutorials