字符串中第一个非数字字符的位置



如何找到字符串中第一个非数字字符的位置?

函数位置似乎不支持正则表达式

position函数不支持正则表达式,所以你应该写更复杂的表达式,或者你可以编写自己的函数

CREATE OR REPLACE FUNCTION public.regexp_position(text, text)
RETURNS integer
LANGUAGE sql
IMMUTABLE STRICT
AS $function$
SELECT position((regexp_match($1, $2))[1] IN $1)
$function$
postgres=# select regexp_position('abcdef123','d');
┌─────────────────┐
│ regexp_position │
╞═════════════════╡
│               7 │
└─────────────────┘
(1 row)
postgres=# select regexp_position('772727a','[^d]');
┌─────────────────┐
│ regexp_position │
╞═════════════════╡
│               7 │
└─────────────────┘
(1 row)

相关内容

最新更新