我有一个文本字段。我需要识别模式<a href
和a>
之间的词。
此模式可以在文本的开头/结尾/中间。
with t as (
select '<a href Part of the technical Network Group www.tech.com/sites/ hh a>' as text from dual
union select '<a href www.tech.technical Network a>' as text from dual union
select 'www.tech.tech///technical <a href Network Group a>' as text from dual)
select * from t
WHERE REGEXP_LIKE(text,'(^|\W)<a href\S*','i')
这给了我前两行结果,这是正确的。但是我需要检查单词“ group”(不区分大小写)。我们如何检查“组”一词以及该模式中的“ with”一词。在这种情况下,应该返回第一行和第三行。
搜索完整的模式,然后在该模式的子字符串中搜索单词Group
:
Oracle设置:
CREATE TABLE table_name ( id, text ) AS
select 1, '<a href Part of the technical Network Group www.tech.com/sites/ hh a>' from dual union all
select 2, '<a href www.tech.technical Network a>' from dual union all
select 3, 'www.tech.tech///technical <a href Network Group a>' from dual;
查询:
WITH positions ( id, text, match ) AS (
SELECT id,
text,
REGEXP_SUBSTR(
text,
'(^|\W)<a href\s+.*?\s+a>(\W|$)',
1,
1,
'i'
)
FROM table_name
)
SELECT id,
text
FROM positions
WHERE REGEXP_LIKE( match, '\s+Group\s+', 'i' );
输出:
ID |文本-:| :------------------------------------------------- -------------------1 | 3 | www.tech.tech///technical
db <>小提琴here