i'm trying the below code to select the last part of the url:
select 'http://www.XX.com/download/apple-Selection-products/beauty-soap-ICs' , field_1[0].string
from
(
select SPLIT('([^\/] $)', 'http://www.XX.com/download/apple-Selection-products/beauty-soap-ICs')field_1
)
however , my result isn't coming as expected.
http://www.XX.com/download/apple-Selection-products/beauty-soap-ICs
result should be : beauty-soap-ICs
but i'm getting
any help will be appreciated. The URL can and can't end in "/"
CodePudding user response:
You can use the REGEXP
function here:
SELECT REGEXP('http://www.XX.com/download/apple-Selection-products/beauty-soap-ICs', '.*/([^/] )/?$', '$1') AS result
See the regex demo
Details:
.*
- any zero or more chars other than line break chars as many as possible/
- a/
char([^/] )
- Group 1 ($1
refers to this group value)" one or more chars other than/
/?
- an optional/
char$
- end of string.