user-pic

regex replace: search pattern from a variable?

Vote 0 Votes

I'd like to do a regex_replace where both the search & replace values are stored in variables. (It's a whole lot neater and useful.)

Storing the replace text in a variable works fine, but not the search text. I'm probably just making an ignorant mistake.

The following is the working code from my Entry template.

<mt:Assets> <mt:AssetLabel setVar="my_asset_label" /> <mt:if name="body_content" like="$my_asset_label"> <mt:SetVarBlock name="new_image_block"> <div class="std_side_image_$4" style="width: 150px;"> <img src="$3" width="" height="" alt="[PHOTOGRAPH] $2" title="[PHOTOGRAPH] $2"> <p>$2</p> </div> </mt:SetVarBlock> </mt:if> </mt:Assets>

<mt:var name="body_content"
regex_replace="/<span class="mt-enclosure .+?><a href="(.+?)"><img alt="(.+?)" src="(.+?)" class="mt-image-(.+?)".+?</span>/g","$new_image_block"
/>

Reported on Movable Type 4.2

2 Replies

| Add a Reply
  • Duh, and I should have specified: the following didn't work:

    <mt:var name="body_content" regex_replace="$some_variable"... <mt:var name="body_content" regex_replace="/$some_variable/"...

    So... how can we put the search pattern into a variable?

    thanks.

  • I repeated my question and got some useful answers in a second post.

    The short answer was: probably can't do this in regex_replace but you can use variables (without anything other text) in a simple replace.

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1773 6162

Last Topic: Excluding categories from blog by kholechek on Feb 9, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1429 5077

Last Topic: What apocalypse hit this community in the middle of 2011? by 75th on Feb 10, 2012

694 2908

Last Topic: Blogspot to Movable Type by sdude on Feb 8, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

173 737

Last Topic: About the MT version stated in HTML source by Alex E. Schneider on Feb 7, 2012

190 565

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012