Title: working with textstrings
Last modified: May 2, 2019

---

# working with textstrings

 *  Resolved [ernstwg](https://wordpress.org/support/users/ernstwg/)
 * (@ernstwg)
 * [7 years ago](https://wordpress.org/support/topic/working-with-textstrings/)
 * I would like to update an spceific textstring within the image caption.
    Caption
   is blablablaREPLACEblablabla . The substring REPLACE should be repaced for instance
   with 2#105:Headline .
 * I am thinking of something like
    replace (in_caption; sub_string; with_headline)
 * Hope you understand 🙂
 * Cheers, Ernst Wilhelm

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [7 years ago](https://wordpress.org/support/topic/working-with-textstrings/#post-11494011)
 * Thanks for an interesting question. MLA does have a simple `,str_replace(s,r)`
   option/format value but it does not support expanding a variable value such as`[
   +iptc:2#105+]` in the replacement portion. For that, you can use the regular 
   expression functions added to resolve this earlier topic:
 * [Sorting a gallery, once again](https://wordpress.org/support/topic/sorting-a-gallery-once-again/)
 * For your application, you can use the `,extract(p,v)` format/option value to 
   break the Caption into three parts; prefix, match (REPLACE) and postfix. Then,
   you can use these parts in a Content Template to assemble your replacement value.
   You can find more information and examples in the “Regular Expression Features”
   section of the Settings/Media Library Assistant Documentation tab.
 * I did some testing to develop a solution for your application and found a couple
   of small defects in the current MLA version. Thank you for giving me the opportunity
   to find and fix these problems. I have uploaded a new MLA Development Version
   dated 20190306 that contains the fixes you will need for your application. You
   can find step-by-step instructions for using the Development Version in this 
   earlier topic:
 * [PHP Warning on media upload with Polylang](https://wordpress.org/support/topic/php-warning-on-media-upload-with-polylang/#post-9625341)
 * Once you have installed the Development Version you can use a Content Template
   to update your Caption values. Here is the template I developed for your application:
 *     ```
       template:([+post_excerpt,extract( '/(?<pre>^.*)(?<match>EXIF)(?<post>.*$)/', pre )+])([+iptc:2#105+]|[+matches:match+])([+matches:post+])
       ```
   
 * The template has three parts. First:
 * `([+post_excerpt,extract( '/(?<pre>^.*)(?<match>REPLACE)(?<post>.*$)/', pre )
   +])`
 * This part takes the Caption value (from the `post_excerpt` database field) and
   applies a regular expression to divide it into three named subpatterns:
    - `(?<pre>^.*)` matches everything from the start of the string up to the start
      of the replacement target.
    - `(?<match>REPLACE)` matches the replacement target.
    - `(?<post>.*$)` matches everything from the end of the replacement target to
      the end of the string.
 * The second argument of the `extract` format/option value, `, pre )`, returns 
   the prefix portion of the Caption. The second template part is:
 * `([+iptc:2#105+]|[+matches:match+])`
 * This part returns the IPTC headline value, if present, or the original replacement
   target if no headline is available. The third part is:
 * `([+matches:post+])`
 * This adds the postfix portion of the original Caption to the final result.
 * You can apply the template on a one-time basis using MLA’s Bulk Edit action in
   the Media/Assistant submenu:
    1. Navigate to the Media/Assistant admin screen.
    2. Check the box to the left of each item you want to edit.
    3. Pull down the “Bulk Actions” control and select “Edit”.
    4. Click “Apply” to open the Bulk Edit Area.
    5. Make the changes you want to apply to the selected items. For example, enter
       the complete template given above in the Caption text box in the right-hand 
       column.
    6. Click “Update” in the lower-right corner of the Bulk Edit area to apply your
       changes.
    7. When the operation is complete, click “Refresh” to see the results.
 * **The above solution has one dangerous property. If you apply the template to
   an item that does NOT contain the “REPLACE” literal the entire Caption will be
   replaced by the IPTC headline and the original content will be lost.** Be careful
   to apply the template only to the items that need updating.
 * It would be great if you can install the Development Version and try the solution
   outlined above. I will leave this topic unresolved until I hear back from you.
   Thanks again for alerting me to this MLA defect and giving me a good example 
   of regular expression processing.
 *  Plugin Author [David Lingren](https://wordpress.org/support/users/dglingren/)
 * (@dglingren)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/working-with-textstrings/#post-11602040)
 * It has been a month since my last post in this topic. I hope the MLA Development
   Version allowed you to accomplish your task.
 * I am marking this topic resolved, but please update it if you have any problems
   or further questions regarding the above suggestions. Thanks for your interest
   in the plugin.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘working with textstrings’ is closed to new replies.

 * ![](https://ps.w.org/media-library-assistant/assets/icon-256x256.png?rev=973502)
 * [Media Library Assistant](https://wordpress.org/plugins/media-library-assistant/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/media-library-assistant/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/media-library-assistant/)
 * [Active Topics](https://wordpress.org/support/plugin/media-library-assistant/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-library-assistant/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-library-assistant/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [David Lingren](https://wordpress.org/support/users/dglingren/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/working-with-textstrings/#post-11602040)
 * Status: resolved