Last active
January 3, 2016 11:18
-
-
Save dharkum/8454979 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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