正则表达式获取点和 space regexp_substr 之间的所有内容

Regex to get everything between a dot and a space regexp_substr

在 Oracle 数据库中,我有一个字符串,例如 12.13 this is a test。使用 regexp_substr 我试图只提取 13。那是点之后 space 之前的数字。我尝试了各种组合,(string, '\.[0-9]{1,}') 最接近,但我仍然得到 .13。有没有办法只 return 13?

数据还包括 1.1 等项目。最多数字会变成 99.99.

所有可能的数字格式为:#.##.####.###.##

鉴于输入字符串总是有前导数字和一个点,可以使用 regexp_substr 提取小数。 regexp_replace 也可以使用。

这里有一些 regexp_substr 的例子。这些工作包括一个针对所需数据的捕获组和一个 subexpression 参数(regexp_substr 中的最后一个参数):

SELECT REGEXP_SUBSTR('12.13 this is a test','^[0-9]{1,}[.]{1}([0-9]{1,})',1,1,NULL,1) AS FRACTIONAL FROM DUAL;

结果:

FRACTIONAL
13

1 row selected.

SELECT REGEXP_SUBSTR('1.1 this is a test','^[0-9]{1,}[.]{1}([0-9]{1,})',1,1,NULL,1) AS FRACTIONAL FROM DUAL;

结果:

FRACTIONAL
1

1 row selected.

SELECT REGEXP_SUBSTR('99.99 this is a test','^[0-9]{1,}[.]{1}([0-9]{1,})',1,1,NULL,1) AS FRACTIONAL FROM DUAL;

结果:

FRACTIONAL
99

1 row selected.

对于此类任务,我 regexp_replaceregexp_substr 更喜欢。

regexp_replace(str, '^.*?\.([[:digit:]]+).*$', '');

即从头开始寻找完整的字符串,包括一些字符、一个点、一些数字、一些字符直到结束,但只记住数字和 return 而不是字符串。

但我想这只是个人喜好问题。

select regexp_substr('12.13 this is a test', '\d+\.(\S+)', 1, 1, null, 1) rs
from dual;

RS
--
13