regexp匹配2个不同的可能输入

ffscu2ro  于 2023-05-23  发布在  Hive
关注(0)|答案(1)|浏览(305)

我想使用一个regexp接受以下两种不同的输入:

schema/table/col1,col2
schema/table

结果就是:

schema/table

我在hiveudf regexp\u extract(stringsubject,stringpattern,int index)中使用了它,在这里我必须给出匹配的索引。
我试过使用 ^([^/]*/){2}|^.* 索引为0,它几乎得到了我想要的。
有输入 schema/table/col1,col2 我明白了 schema/table/ ,但我不想要第二个 / .
有输入 schema/table 我明白了 schema/table ,这就是我想要的。
另外,“schema”、“table”、“col”等都是占位符。我不想硬编码任何文本或文本长度。
参考文献:https://cwiki.apache.org/confluence/display/hive/languagemanual+udf

q1qsirdb

q1qsirdb1#

适当的正则表达式是: (^[^\/]+)\/([^\/]+) 这将返回两个具有各自值的捕获组。

相关问题