Skip to content

Instantly share code, notes, and snippets.

@dharkum
Last active January 3, 2016 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dharkum/8454979 to your computer and use it in GitHub Desktop.
Save dharkum/8454979 to your computer and use it in GitHub Desktop.
package HiveUDF;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.hadoop.hive.ql.exec.UDF;
public final class FindPattern extends UDF
{
public static String evaluate(String targetString, String strPattern)
{
// Pattern matching on the input pattern
Pattern p = Pattern.compile(strPattern);
Matcher m = p.matcher(targetString);
String res=null;
// if we find a match, get the group
if (m.find())
{
// Get the first group that matches
res= m.group(0);
return(res);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment