Monthly Archives: July 2017

Java Code To Extract Email From Text

I found a good piece of code which can be used to extract multiple email from a String. A modified version of the code is listed below:

public static String readContactEmailFromString(String resumeText) {
    final String RE_MAIL = "([\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Za-z]{2,4})";
    Pattern p = Pattern.compile(RE_MAIL);
    Matcher m = p.matcher(resumeText);

    StringBuilder sb = new StringBuilder();
    while(m.find()) {
        if (sb.toString().contains(m.group(1))) continue;
        if (sb.toString().isEmpty()) {
            sb.append(m.group(1));
        } else {
            sb.append("; " + m.group(1));
        }
    }
    return sb.toString();
}

Fetching colleague’s fork on Github

I am currently using Github and all project members have forked the main repository into private repository. Now the problem is that I need to review my colleagues code committed in his branch inside his forked repository. So to do this I found out a good article that showed me exactly how to do that. I used the following approach.

git remote add my-colleague https://github.xyz.com/my-colleague/project.git

git fetch my-colleague

git checkout -b my-colleague-branch --track my-colleague/branch

After I do this I can see all the work done by my colleague and I can switch back to my branch anytime.