0

find

[video=youtube;RrI-3vt5VnE]https://www.youtube.com/watch?v=RrI-3vt5VnE[/video]

replace with

[MEDIA=youtube]RrI-3vt5VnE[/MEDIA]

like wise

3
  • like wise tried anything? Commented Apr 2, 2015 at 9:19
  • i mean my String will be in this pattern [video=youtube;RrI-3vt5VnE]youtube.com/watch?v=RrI-3vt5VnE[/video] and i have to replace with [MEDIA=youtube]RrI-3vt5VnE[/MEDIA] using regular expression in php Commented Apr 2, 2015 at 9:27
  • @JunedAnsari: Please update the question with expected output. I guess you are not speaking about regex101.com/r/sM6tK3/1 ? Or is it what you need? Commented Apr 2, 2015 at 10:03

2 Answers 2

1

In php you can use preg_replace like this:

$strData = 'jdlsgvb345454kasjvb [video=youtube;RrI-3vt5VnE]https://www.youtube.com/watch?v=RrI-3vt5VnE[/video]vsdkjgvhs4533davlnasdjkvb';
    //random data containing one matched string

$outputData = preg_replace("#\[video=youtube;([^\]]+)[^\[]+\[/video\]#",
   '[MEDIA=youtube]$1[/MEDIA]', $strData);
Sign up to request clarification or add additional context in comments.

Comments

1

You can do as follows:

var str = '[video=youtube;RrI-3vt5VnE]https://www.youtube.com/watch?v=RrI-3vt5VnE[/video]';

var pattern = /\[video=youtube;([^\]]+)\].*\[\/video\]/;

var output = str.replace(pattern,'[MEDIA=youtube]$1[/MEDIA]');

Jsfiddle link : https://jsfiddle.net/samirkumardas/yaqsr7tu/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.