Jump to content

Help with a regex expression


bms231

Recommended Posts

ok so i don't know php but a friend told me this is the place to ask.... so this is what i am doing....

 

i need to grab the string after /video/ and before .htm

 

http://videos.streetfire.net/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm

 

so i can make a string like this

 

        http://videos.streetfire.net/vidiac.swf?video=bceb6963-b1b7-4ced-9075-423ce6135921

 

 

 

here is where i am trying to do it:

 

if (preg_match('/video/(.*)$/', $this->_mediaInfo['url'], $match))

 

 

^^^  i know this is not right.  what should it be?  i need to use preg_match.

 

Link to comment
https://forums.phpfreaks.com/topic/49737-help-with-a-regex-expression/
Share on other sites

$pattern = "#\/video\/(.*)\.htm#";

 

That should work... I'll test it in a second....

 

Edit: just tested it and

$url = "http://videos.streetfire.net/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm";
$pattern = "#\/video\/(.*)\.htm#";
if(preg_match($pattern, $url, $match)) {
echo $match[1];
}

returns "bceb6963-b1b7-4ced-9075-423ce6135921"

o darn one thing i forgot to add is it has to be able to detect the '-' as well

 

i am doing detection on multiple strings and streetfire is the only url w/ - in it so i figure that is what i will use to determine if it is streetfire or not.

 

 

 

 

this would be a wish, i think i may be able to use ur solution already unless u wanna try and verify the -

$pattern = "#\/video\/(.*)\.htm#";

 

That should work... I'll test it in a second....

 

Edit: just tested it and

$url = "http://videos.streetfire.net/video/bceb6963-b1b7-4ced-9075-423ce6135921.htm";
$pattern = "#\/video\/(.*)\.htm#";
if(preg_match($pattern, $url, $match)) {
echo $match[1];
}

returns "bceb6963-b1b7-4ced-9075-423ce6135921"

 

 

 

so basically it would look like this?

 

if (preg_match('/video\/(.*)\.htm', $this->_mediaInfo['url'], $match) {

You could use something like the following to determine if it has a - in it.  If you wanted to split the string based on -'s you could use explode (http://php.net/explode).

if(strpos($url, "-") !== false) {
//its a streetfire url... or well... it has a - in it anyway ;p
}

 

Edit: forgot to answer your question.

 

so basically it would look like this?

 

if (preg_match('/video\/(.*)\.htm', $this->_mediaInfo['url'], $match) {

 

That would be the basic syntax of it, but that regexp is incorrect.  It will generate a warning ;p.

 

It would interpret / as a delimiter instead of the the beginning of /video/.

 

You could use something like "/\/video\/(.*)\.htm\/", but the regexp you said would not work.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.