Plpgsql: Assign regular expression match to variable

Поиск
Список
Период
Сортировка
От Leif B. Kristensen
Тема Plpgsql: Assign regular expression match to variable
Дата
Msg-id 200909011401.00231.leif@solumslekt.org
обсуждение исходный текст
Ответы Re: Plpgsql: Assign regular expression match to variable  (Ian Barwick <barwick@gmail.com>)
Список pgsql-sql
In Plpgsql, I've got this problem of how to assign an integer extracted 
from a regex to a variable. My approach so far feels kludgy:

-- extract ^#(\d+) from txt
IF txt SIMILAR TO E'#\\d+%' THEN   my_int := SUBSTR(SUBSTRING(txt, E'#\\d+'), 2,       LENGTH(SUBSTRING(txt, E'#\\d+'))
-1)::INTEGER;  -- strip ^#\d+ from text   my_txt := REGEXP_REPLACE(txt, E'^#\\d+ ', '');
 
END IF;

What I'd like to do is something like this:

my_int := MATCH(txt, '^#(\d+)')::INTEGER;

which would assign the integer atom (\d+) to my_int.
-- 
Leif Biberg Kristensen | Registered Linux User #338009
Me And My Database: http://solumslekt.org/blog/


В списке pgsql-sql по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: PostgreSQL Function: how to know the number of the returned results of the Query
Следующее
От: Ian Barwick
Дата:
Сообщение: Re: Plpgsql: Assign regular expression match to variable