在两个已知字符串/字符集之间提取字符串/字符

ftf50wuq  于 2021-06-02  发布在  Hadoop
关注(0)|答案(0)|浏览(316)

我想从列(name=description)中的两个已知字符串(“hostname:”和“host alias:”)之间获取一个字符串(服务器名称)
样本数据为
我们收到了警报service:xx-iosdoh_free.usershostname:pugsxxdsbudlp01.eeehost别名:894.aa
我对regex的查询:(它带来了空值)

select regexp_extract(description, 'regex (?<=Hostname:).*?(?=Host Alias:), 1)', 
from tableA 
where number = '554';

我的子字符串查询:(带空值)

select substring(description, (locate('Hostname: ', description) + 8), (locate('Host Alias:', description) - 1) - (locate('Hostname: ', description) + 8)) as 'Server_Name'
from tableA 
where number = '554';

如果我运行查询在“we”和“alert”之间搜索string=we received alert….,那么我会在结果中找到“received”,因为“we”和“alert”前后都有空格,并且被视为单词。
如果你有更好的方法来完成我的任务,那我怎么用字符串(没有单词)搜索呢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题