Search code examples
sqlregexoracle11gpattern-matchingsubstr

How to check if the word is a part of the string starting from www always using regex?


I have a text value which has a URL as part of it in every text. How do I identify if the word technical is part of the link?

create table t as 
select 'Part of the technical Network Group www.technical.com/sites/' as text from dual
union select 'Technical Network Group' as text from dual;

select * from t
where regexp_like(text,'technical','i')

I am getting both the texts. I need just the first text. The link may differ it can be www.tech.technical as well.


Solution

  • You may use

    WHERE REGEXP_LIKE(text,'www\.\S*technical','i')
    

    Or, if you also want to consider the URL can start with http or https,

    WHERE REGEXP_LIKE(text,'(https?://|www\.)\S*technical','i') 
    

    Details

    • www\. - a www. substring
    • \S* - 0+ chars other than whitespace
    • technical - a technical substring.

    See the online demo:

    with testdata(text) as (
          select 'Part of the technical Network Group www.technical.com/sites/'  from dual
          union
          select 'Part of the technical Network Group www.some.com/sites/technical'  from dual
          union
          select 'Technical Network Group' from dual
       )
    select * from testdata where regexp_like(text,'www\.\S*technical','i') 
    

    Output:

    enter image description here

    See another demo with http/https support.