I need to remove part of a URL with a regex. From the words: http or https to the word .com. And it can be several times in one string. Can anyone help me with this?
For example a string: "The request is:https://stackoverflow.com/questions" After the removal - "The request is:/questions"
CodePudding user response:
The regex that performed the deletion perfectly is: (@"\w ://[^/$]*") with replace "".
Something like that:
var regex = new Regex(@"\w :\/\/[^\/$]*");
regex.Replace(url, "");
CodePudding user response:
You can use the re.sub()
function from the regex package. Alternatively if your working with python you can use urlparse
package to extract different parts of the url and concatenate it to the prefix you want.