Regex for extract for url path
NickName:xiaohouzi Ask DateTime:2019-10-17T15:51:50

Regex for extract for url path

I need help with creating a regex for PostgresSQL to extract specific url paths and place them into a separate column.

For example, using the following URLs I need to extract

https://example.com/drinks/ 
https://example.com/drinks/beverages/
https://example.com/drinks/beverages/pepsi/pepsi-can-16-oz/
Column 1                                                   | Column 2
---------------------------------------------------------------------------------------
https://example.com/drinks                                 | /drinks/
https://example.com/drinks/beverages                       | /drinks/beverage/
https://example.com/drinks/beverages/pepsi/pepsi-can-16-oz | /drinks/beverages/pepsi/

And lastly, a regex to get anything after /drinks/beverage/*...

Regex isn't my strong suit so I'm looking for some guidance on how to accomplish this.

Copyright Notice:Content Author:「xiaohouzi」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58427542/regex-for-extract-for-url-path

More about “Regex for extract for url path” related questions

Regex to extract first word in a url path

I have this regex to extract the application name out of the url path \/(?<app>[^\.\/]+)[\/\?] /foo/bar -> foo /foo?bar=x -> foo However, this is not found /foo How can I imp

Show Detail

Regex for extract for url path

I need help with creating a regex for PostgresSQL to extract specific url paths and place them into a separate column. For example, using the following URLs I need to extract https://example.com/

Show Detail

How to extract path from URL using Regex?

I want to extract path from url. www.abc.com/contact/abc => /contact www.abc.com/contact.abc/asdsad => /contact.abc www.abc.com/contact-abc.html/asdsad => /contact-abc.html www.abc.com/

Show Detail

How to extract part of an URL path in regex

In my url that might look like this: protocol://server/path1/path2/path3/pathn/key/id1234567890?Create I want to get the value id1234567890 (via a group) but I don't know how many "path" parts th...

Show Detail

How to use regex to extract the relative path of a url without path params or query params?

With NodeJS environment, how would you extract the relative path, while also not accounting for numeric path params, and all query params? Say you have a url as a string: https://localhost:8000/api...

Show Detail

How extract path from string using regex

How do I extract /path/index.html from following string url("/path/index.html") url(/path/index.html) I using following regex, but don't work. Pattern.compile("\\b(href=|url\\()([\"\'])(([^/]&#x

Show Detail

Regex - Extract path from url without last /

I have following regex expression (.*[\/]) This will match /path/tooo/url/ from this string /path/tooo/url/blablabla-xxxxx My question is how to modify regex to match /path/tooo/url

Show Detail

How to extract a substring of a URL with regex

Working with some unstructured data and hoping to extract utm_campaign names from URLs. Here's an example of one URL. I'd like to extract the name following "utm_campaign=" but before &qu...

Show Detail

Extracting data from URL path via regex

I am trying to extract data from a URL path as follows: /12345678901234567890123456789012/1230345035/wibble/wobble/ With this regex i can extract into 3 groups with this regex: \/([^\/]*)\/([^\/...

Show Detail

Extract url with Regex

I've a regex to extract an url but sometime it doesn't work. Here is my regex @"((https?|ftp|file)\://|www.)[A-Za-z0-9\.\-]+(/[A-Za-z0-9\?\&\=;\+!'\(\)\*\-\. _~%]*)*" And here an url that do

Show Detail