我正在尝试使用 Oracle 12c regexp_substr 从字符串中提取单词,但没能理解它的工作原理,网络中的信息太多,我很困惑。
所以我想从字符串中提取 tmp*
表:
query_str
:
select
column1 c1,
column2 c2
from tmp_123 foo1, -- some comments here
TAB1_123 TAB1
where 1=1
;
尝试使用这个但没有“运气”:
select regexp_substr(query_str, 'TMP_[A-z]+', 1, 1, 'i');
我想提取直到空格和 tmp 表名称中间可以有数字,如下所示:tmp_123
。
有什么建议吗?
最佳答案
您可以使用两者之一:
select regexp_substr(query_str, 'TMP_\w+', 1, 1, 'i');
select regexp_substr(query_str, 'TMP_\S+', 1, 1, 'i');
\w+
将匹配 TMP_
之后的字母数字或下划线字符,\S+
将匹配一个或多个非空白字符。
请参阅\w
regex demo和 \S
regex demo .
关于regex - 如何使用 Oracle regexp_substr 从字符串中提取单词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67532974/