All Forums General
Johnmghenry 11 posts Joined 04/15
11 Jun 2015
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?

dnoeth 4628 posts Joined 11/04
11 Jun 2015

You just need to change a slash to a backslash:

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

 

Dieter

Johnmghenry 11 posts Joined 04/15
12 Jun 2015

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.
 

Johnmghenry 11 posts Joined 04/15
12 Jun 2015

apologies, the adjusted function looks like
 
regexp_substr(fullurl ,'(?<=(\?page_id\=|/page_id/))(.*?)(?=\&)' ,1 ,1, 'i')

dnoeth 4628 posts Joined 11/04
12 Jun 2015

Switch the square to round brackets:

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

 

Dieter

You must sign in to leave a comment.