Finding a substring between two points

General
Enthusiast

Finding a substring between two points

I have  a string which looks like 

"/channel/featured?page_id=this_is-the_text-that_I_want&rest_of_the_query"

I'm trying to extract just 'this_is-the_text-that_I_want',

I thought it might look like regexp_substr(field_text ,'(?<=/?page_id\=)(.*?)(?=\&)' ,1 ,1, 'i')

But I get a message saying this is not a pattern.

Can someone help clarify who I pass a pattern into regexp_substr?

Tags (2)
4 REPLIES
Junior Contributor

Re: Finding a substring between two points

You just need to change a slash to a backslash:

regexp_substr(field_text ,'(?<=\?page_id\=)(.*?)(?=\&)' ,1 ,1, 'i')
Enthusiast

Re: Finding a substring between two points

Thanks Dieter, I hope you don't mind, I have a little additional question

What if I wanted to find more than on variant, could this work

regexp_substr(field_text ,'(?<=\?[page_id|shop_id]\=)(.*?)(?=\&)' ,1 ,1, 'i')

In this example I'm also capturing any text between shop_id and the '&' symbol.

Enthusiast

Re: Finding a substring between two points

apologies, the adjusted function looks like

regexp_substr(fullurl ,'(?<=(\?page_id\=|/page_id/))(.*?)(?=\&)' ,1 ,1, 'i')

Junior Contributor

Re: Finding a substring between two points

Switch the square to round brackets:

REGEXP_SUBSTR(fullurl ,'(?<=\?(page|shop)_id\=)(.*?)(?=\&)' ,1 ,1, 'i')