Skip to content

Instantly share code, notes, and snippets.

@dharkum
Last active Jan 3, 2016
Embed
What would you like to do?
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