This question requires knowledge of Perl, Movable Type, and the MT
Regex and MT Encloures plug-ins.
http://bradchoate.com/weblog/2002/07/27/mtregex
MT Enclosures generates a list of URLs for media files in this format:
http://www.example.com/example/file.mp3
MT Regex allows you to search and replace text using Perl expressions.
I'm hoping someone can show me the syntax to use MT Regex to truncate
URLs like http://www.example.com/example/file.mp3 into just the file
name "file.mp3" for output in a Movable Type template. |
Request for Question Clarification by
palitoy-ga
on
16 Dec 2005 11:52 PST
Hello dotnaught-ga
I don't have MT and MT Regex installed on this PC but this Perl
regular expression should match "file.mp3":
/\/.*\/.*\/(.*)$/
Let me know if that is of help or if you still require further
assistance. I will be able to provide full support tomorrow when I
have my PC with MT installed.
palitoy-ga
|
Clarification of Question by
dotnaught-ga
on
17 Dec 2005 15:16 PST
What I'm hoping for is a way to use that regular expression in the MT
Regex syntax. Here's any example of something ought to work but
doesn't:
<$MTEnclosureURL regex="s/<$MTEnclosureURL$>/XYZ/g"$>
The result is on this page under "podcasts" in the right hand column:
http://www.lot49.com/testpage.shtml
I had hoped it would replace the full URL generated with XYZ rather
than adding it. XYZ, ultimately, is should be just the file name, not
the full URL.
If I do <$MTEnclosureURL regex="s/vint/vinton/g"$>
it will work on the URL that matches though I don't know why.
Can you think of a way that /\/.*\/.*\/(.*)$/
will work in this format (or some other way that works with MT Regex)?
<$MTEnclosureURL regex="s/<$MTEnclosureURL$>/XYZ/g"$>
|
Request for Question Clarification by
palitoy-ga
on
18 Dec 2005 02:56 PST
Re: <$MTEnclosureURL regex="s/<$MTEnclosureURL$>/XYZ/g"$>
I am not sure about this, it sounds like you need to escape the $
characters in the regular expression to make it something like this:
<$MTEnclosureURL regex="s/\<\$MTEnclosureURL\$\>/XYZ/g"$>. This might
send it into some sort of horrible loop though!
Did you try this tag:
<$MTEnclosureURL regex="s/\/.*\/.*\/(.*)$/$1/g"$>
This should match the filename from the URL and replace the URL with the filename.
|
Clarification of Question by
dotnaught-ga
on
18 Dec 2005 08:50 PST
Ah, very close. All that remains is to remove the "http:" that
precedes the file name.
See
http://www.lot49.com/testpage.shtml
for the results of
<$MTEnclosureURL regex="s/\/.*\/.*\/(.*)$/$1/g"$>
under the 'Podcasts' JS pulldown menu.
It surprises me that that works. The Regex docs say: You cannot use
the letter '$' inside an inline expression due to a parsing limitation
of Movable Type 2.21 (an old version so perhaps v3.2 has fixed this).
It says in order to use a '$' in your expressions, you need to use th
MTRegexDefine tag.
But I'm not complaining :-)
|
Request for Question Clarification by
palitoy-ga
on
19 Dec 2005 03:55 PST
Sorry for the slow responses to this, I am not receiving the
notifications I normally do when someone responds to one of my
question clarification requests.
To remove the http: part you could use something like this:
<$MTEnclosureURL regex="s/^http\:\/.*\/.*\/(.*)$/$1/g"$>
The ^ and $ have specific meanings in regular expressions - meaning
the beginning and ending of a string. You can add/remove these to
adjust the sensitivity of the regular expression.
Let me know how you get on with this and if it solves your problem.
|
Clarification of Question by
dotnaught-ga
on
19 Dec 2005 06:42 PST
That does it. Thanks much! If there's anything further I need to do to
mark this question answered, please let me know.
|