|
@@ -0,0 +1,48 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
+
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: XuJiakai
|
|
|
+ * 2020/11/2 10:16
|
|
|
+ * 注册资本提取
|
|
|
+ */
|
|
|
+public class RegisteredCapitalTrim extends UDF {
|
|
|
+ private static boolean isDouble(String val) {
|
|
|
+ try {
|
|
|
+ Double.parseDouble(val);
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final Pattern pattern = Pattern.compile("[^0-9.]");
|
|
|
+
|
|
|
+
|
|
|
+ public String evaluate(String val) {
|
|
|
+ if (StringUtils.isEmpty(val)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (val.contains("%")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Matcher matcher = pattern.matcher(val);
|
|
|
+ try {
|
|
|
+ String a = matcher.replaceAll(" ").split("\\s+")[0];
|
|
|
+ return StringUtils.isNotBlank(a) ? isDouble(a) ? a : null : null;
|
|
|
+ } catch (ArrayIndexOutOfBoundsException exception) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String a = new RegisteredCapitalTrim().evaluate("50万元人民币");
|
|
|
+ System.out.println(a);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|