В ваших последующих ответах на ФП вы спрашивали о том, может ли длина ключа отличаться от семи.В дополнение к решению, позволяющему сопоставить ровно семь цифр после REQ #
, здесь представлены некоторые варианты этой темы, чтобы проиллюстрировать изменяющиеся спецификации длины числа после ключевого слова.
with q as (
select 'WHAT COULD BE THE REQ # 2145673' as sentence from dual union all
select 'HOW MANY REQ# 1234673 COULD BE THERE' as sentence from dual union all
select 'REQ# 2398723 OR THE SECOND REQ#' as sentence from dual union all
select 'GEARREQ#1232124' as sentence from dual union all
select 'REQ # 1234567, REQ# 1234886' as sentence from dual union all
select 'REQ # 1, REQ# 1234886' as sentence from dual union all
select 'REQ # 123, REQ# 1234886' as sentence from dual union all
select 'REQ # 123456789, REQ# 1234886' as sentence from dual union all
select 'REQ # 1234567890, REQ# 1234886' as sentence from dual
)
select sentence,
-- Locating just the key characters, allows you to accomodate
-- variable length numbers following the key characters.
regexp_substr(sentence,'REQ *# *',1) as keyword_find,
regexp_substr(sentence,'REQ *# *[[:digit:]]+',1) as keyword_then_any_digits,
regexp_substr(sentence,'REQ *# *[[:digit:]]{7}',1) as kw_match_exatly_seven,
regexp_substr(sentence,'REQ *# *[[:digit:]]{1,7}',1) as kw_match_1_to_7_digits,
regexp_substr(sentence,'REQ *# *[[:digit:]]{3,10}',1) as kw_match_3_to_10_digits,
-- Some additional formatting will remove excess spaces and render output to specs.
--- First regexp_substr selects the relevant text to format.
-- Second regexp_substr grabs the number portion of relevant text.
-- Then just append REQ# to front of that number.
'REQ# ' || regexp_substr(regexp_substr(sentence,'REQ *# *[[:digit:]]{7}',1),'[[:digit:]]+') as format_exactly_7
from q;