Google Answers Logo
View Question
Q: Movable Type/Perl/MT Regex Syntax Question ( Answered 5 out of 5 stars,   1 Comment )
Subject: Movable Type/Perl/MT Regex Syntax Question
Category: Computers > Programming
Asked by: dotnaught-ga
List Price: $40.00
Posted: 16 Dec 2005 08:51 PST
Expires: 15 Jan 2006 08:51 PST
Question ID: 606527
This question requires knowledge of Perl, Movable Type, and the MT
Regex and MT Encloures plug-ins.

MT Enclosures generates a list of URLs for media files in this format:

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 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.


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

<$MTEnclosureURL regex="s/<$MTEnclosureURL$>/XYZ/g"$>

The result is on this page under "podcasts" in the right hand column:

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.


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.
Subject: Re: Movable Type/Perl/MT Regex Syntax Question
Answered By: palitoy-ga on 19 Dec 2005 11:13 PST
Rated:5 out of 5 stars
Hello dotnaught-ga,

Thank-you for your question and your patience whilst I sorted out this
problem for you.  By answering the question here I have marked the
question as answered and there is nothing further for you to do
(except leave feedback/tip if you so wish).

The code you required to solve your problem was:

<$MTEnclosureURL regex="s/^http\:\/.*\/.*\/(.*)$/$1/g"$>

If you require any further assistance on this subject please do not
hesitate to ask for clarification and I will be happy to help further.
dotnaught-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Very helpful, thank you.

Subject: Re: Movable Type/Perl/MT Regex Syntax Question
From: palitoy-ga on 19 Dec 2005 11:50 PST
Thanks for the 5-star rating and tip.  They are both appreciated.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  

Google Home - Answers FAQ - Terms of Service - Privacy Policy