如何在配置单元中替换正则表达式的一部分
How to replace part of a regex in hive
我尝试使用配置单元 regexp_replace 执行以下操作但没有成功:
转型:
/foo1/foo2/foo3-bar1/p-115390-20.html' or '/foo1/foo2/foo3-bar1/p-115390-35.html
转化为:/foo1/foo2/foo3-bar1/p-115390.html
知道我有这样的网址
/foo1/foo2/foo3-bar1/p-115390.html
我不想被改造:
/foo1/foo2/foo3-bar1/p-115390.html
保持 /foo1/foo2/foo3-bar1/p-115390.html
我试过没有成功:
SELECT regexp_replace('/foo1/foo2/foo3-bar1/p-115390-20.html', 'p\-\d+(\-\d+\).html', '')
数字 115390 或 115390-20 当然可以是任何数字。
这是一道 ORACLE 题吗? (你没有标记你的 DBMS)你可以试试这个
SELECT REGEXP_REPLACE(COLUMNNAME,'(\/foo1\/foo2\/foo3\-bar1\/p-\d+)\-\d+\.html','.html')
或
SELECT REGEXP_REPLACE('/foo1/foo2/foo3-bar1/p-115390-20.html','(\/foo1\/foo2\/foo3\-bar1\/p-\d+)\-\d+\.html','.html')
最后,一个较短的版本可能也一样。这取决于你的匹配需要多严格。
SELECT REGEXP_REPLACE('/foo1/foo2/foo3-bar1/p-115390-20.html','(p-\d+)\-\d+\.html','.html')
找到答案:SELECT REGEXP_REPLACE('/foo1/foo2/foo3-bar1/p-115390-20.html','(p+\-+[0-9]+)\-+ [0-9]+\.+html$','$1\.html')
再次感谢您的帮助
我尝试使用配置单元 regexp_replace 执行以下操作但没有成功:
转型:
/foo1/foo2/foo3-bar1/p-115390-20.html' or '/foo1/foo2/foo3-bar1/p-115390-35.html
转化为:/foo1/foo2/foo3-bar1/p-115390.html
知道我有这样的网址
/foo1/foo2/foo3-bar1/p-115390.html
我不想被改造:
/foo1/foo2/foo3-bar1/p-115390.html
保持 /foo1/foo2/foo3-bar1/p-115390.html
我试过没有成功:
SELECT regexp_replace('/foo1/foo2/foo3-bar1/p-115390-20.html', 'p\-\d+(\-\d+\).html', '')
数字 115390 或 115390-20 当然可以是任何数字。
这是一道 ORACLE 题吗? (你没有标记你的 DBMS)你可以试试这个
SELECT REGEXP_REPLACE(COLUMNNAME,'(\/foo1\/foo2\/foo3\-bar1\/p-\d+)\-\d+\.html','.html')
或
SELECT REGEXP_REPLACE('/foo1/foo2/foo3-bar1/p-115390-20.html','(\/foo1\/foo2\/foo3\-bar1\/p-\d+)\-\d+\.html','.html')
最后,一个较短的版本可能也一样。这取决于你的匹配需要多严格。
SELECT REGEXP_REPLACE('/foo1/foo2/foo3-bar1/p-115390-20.html','(p-\d+)\-\d+\.html','.html')
找到答案:SELECT REGEXP_REPLACE('/foo1/foo2/foo3-bar1/p-115390-20.html','(p+\-+[0-9]+)\-+ [0-9]+\.+html$','$1\.html')
再次感谢您的帮助