Jump to content

use regex to replace string in URL with something else

babadoctor
Go to solution Solved by trag1c,

you could probably use 

\byoutube\.com\b

This uses word boundaries so that it will match what's between the \b. The escape before the period is that it will match the period and not any character at that position. 

 

So with a string replace function you should be able to substitute the matched regex without messing with the rest of the URL.

 

image.thumb.png.4f07fb23b92c05f1fa7e079969ecdba6.png

https://regex101.com/

how do I use regex to replace a certain part of a string and nothing else?

 

i want youtube.com links to get auto redirected to yewtu.be links.

 

for example

https://www.youtube.com/watch?v=R7CO9v9rpOk

i want this link to redirect to

https://www.yewtu.be/watch?v=R7CO9v9rpOk

 

the only difference in the links is the domain name. How can I accomplish the replacement with regex?

 

I tried this but it didn't work

 

image.png.a407578b23cefc86c3a5b3b671724aec.png

OFF TOPIC: I suggest every poll from now on to have "**CK EA" option instead of "Other"

Link to comment
Share on other sites

Link to post
Share on other sites

you could probably use 

\byoutube\.com\b

This uses word boundaries so that it will match what's between the \b. The escape before the period is that it will match the period and not any character at that position. 

 

So with a string replace function you should be able to substitute the matched regex without messing with the rest of the URL.

 

image.thumb.png.4f07fb23b92c05f1fa7e079969ecdba6.png

https://regex101.com/

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×