We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Find and Replace Plus

Development and Programming

smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill

I didn’t break it! 😉 Seems to be working now. Thanks again.

       
RJB's avatar
RJB
35 posts
15 years ago
RJB's avatar RJB

I have a template in ExpressionEngine setup to act as a TXT export of weblog entry data. Since the dataset contains a lot of natural language punctuation (commas, apostrophes, spaces, line breaks, etc.), I am using pipes to act as the delimiter between custom fields.

What I’d like to do is remove all of the line breaks [that’s contained in the custom fields] and replace them with spaces, so the information from the rendered template has each result on a single line. For example:

Heading || Heading || Heading
Line 1 || Data || Data || Data
Line 2 || Data || Data || Data
Line 3 || Data || Data || Data
Line 4 || Data || Data || Data
Line 5 || Data || Data || Data

Much of the data often contains intermixed soft and hard returns (and other special characters pasted from Microsoft Word documents no less!), so the actual export looks more like:

Heading || Heading || Heading
Line 1 || Data || Data || Data
Line 2 || Data || Data
|| Data
Line 3 || Data || Data


|| Data
Line 4 || Data || Data || Data
Line 5 || Data || Data || Data

When using the Find & Replace Plus plugin, I can find one or more newlines with the following Regular Expression:

{exp:replace_plus find="\\n+" replace=" " regex="yes"}

What I’d like help with is determining the Regular Expression to remove all types of newlines and linebreaks (\r, \n, \r\n, soft returns, hard returns, etc) and allow a single line per result from the weblog entries loop.

Does anyone have experience using the Find & Replace Plus plugin to accomplish this?

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi Ryan,

Maybe Oliver Heine’s Strip Linebreaks plugin can help you?

       
ee_sa's avatar
ee_sa
56 posts
15 years ago
ee_sa's avatar ee_sa

Hi

Why can’t I put search term inside Find?

{exp:replace_plus find="{exp:search:keywords}" replace="<h1>{exp:search:keywords}</h1>"}
{exp:replace_plus}

If I put it manually, then its OK.

Thanks in advance 😊

       
RJB's avatar
RJB
35 posts
15 years ago
RJB's avatar RJB
Maybe Oliver Heine’s Strip Linebreaks plugin can help you?

Brilliant, thank you – the plugin worked perfectly for my needs.

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi ee_sa,

Your code should be

{exp:replace_plus find=":LD:exp:search:keywords:RD:" replace="<h1>:LD:exp:search:keywords:RD:</h1>" parse="inward"}
{/exp:replace_plus}
       
brittanyA's avatar
brittanyA
184 posts
15 years ago
brittanyA's avatar brittanyA

Hi Laisvunas, I’d had trouble with Low’s find and replace plugin, so I thought I’d give this one a whirl. It’s not working at all! Here’s my code:

{exp:html_strip keep="strong,em,p,h2,ul,ol,li,a,div"}{exp:replace_plus find="<div class=QUOTEimagerightQUOTE.*?div>|<div class=QUOTEimagecenterQUOTE.*?div>|<div class=QUOTEimageleftQUOTE.*?div>" replace="" regex="yes" multiple="yes"}{article_body}{/exp:replace_plus}{/exp:html_strip}

What am I doing wrong?? Thank you!

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi,

Two things I find wrong in your code:

1) If you need to change something with empty string, you should not use “replace” parameter;

2) you should use not QUOTE but :QUOTE:

       
brittanyA's avatar
brittanyA
184 posts
15 years ago
brittanyA's avatar brittanyA

Thank you! I changed my code to this:

{exp:replace_plus find="<div class=:QUOTE:articleside:QUOTE:.*?div>|<div class=:QUOTE:imageright:QUOTE:.*?div>|<div class=:QUOTE:imagecenter:QUOTE:.*?div>|<div class=:QUOTE:imageleft:QUOTE:.*?div>" regex="yes" multiple="yes"}{article_body}{/exp:replace_plus}

And it works…except, as you can see, I added an additional parameter including the “articleside” div. The plugin is replacing all of the divs except for this one. Is there a reason for this? You can see this in action here: http://uvamagazine.org/mobile/article/this_old_academical_village/

The “articleside” div surrounds the paragraphs starting with “Handyman’s Delight”

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi,

you might need to escape quotes:

{exp:replace_plus find="<div class=\\:QUOTE:articleside\\:QUOTE:.*?div>|<div class=\\:QUOTE:imageright\\:QUOTE:.*?div>|<div class=\\:QUOTE:imagecenter\\:QUOTE:.*?div>|<div class=\\:QUOTE:imageleft\\:QUOTE:.*?div>" regex="yes" multiple="yes"}{article_body}{/exp:replace_plus}

In case your regex pattern gets complicated you would better to check if it works in some program such as RegexBuddy, or in pure PHP and only then use it as plugin’s parameter.

       
smartpill's avatar
smartpill
456 posts
15 years ago
smartpill's avatar smartpill

Is there a way to do a wildcard? I’m using this to strip out LG Replace tags in the meta description and it would be great if I could replace a number with a wildcard. Currently I’m specifying:

{exp:replace_plus find="'|:QUOTE:|:LD:media_1:RD:|:LD:media_2:RD:|:LD:media_3:RD:|:LD:media_4:RD:|
:LD:media_5:RD:|:LD:media_6:RD:|:LD:media_7:RD:|:LD:media_8:RD:"

so you see how a wildcard would be quite handy.

       
fjldude's avatar
fjldude
50 posts
15 years ago
fjldude's avatar fjldude

I’d like to find all occurrences of the titles of a weblog. Can I populate the find parameter via an embedded template (or some other method) that creates a string something like “title1|title2|title3|title4″?

I tried, but didn’t have any luck.

I’m pondering ways to build an illustrated glossary that is easy for the client to maintain and whose terms can be automatically converted to links in any body of text.

Any advice would be appreciated.

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas
Can I populate the find parameter via an embedded template (or some other method) that creates a string something like “title1|title2|title3|title4″?

You cannot populate parameter via an embedded template because embedded template is pased after the main template.

To create the string like “title1|title2|title3|title4″ the plugin Value Aggregator might be helpful.

       
fjldude's avatar
fjldude
50 posts
15 years ago
fjldude's avatar fjldude

Hi Laisvunas,

Thanks, but Value Aggregator doesn’t seem to be applicable my case. I would like to find all the text that occurs in several custom fields of one weblog that match the titles of a second weblog.

I tried Fresh Variables but that didn’t seem to work. Making a Fresh Variable to create the list of titles of the second weblog (title1|title2|title3|title4|…) was no problem (I used the query module to create the list of 150 titles). But I couldn’t get the fresh variable to work as a find parameter in a single-entry template for the first weblog:

{exp:replace_plus find="{myFreshVariable}”}

Is this still an issue of parsing order? or maybe my implementation? Any suggestions?

Thanks again.

       
Sean C. Smith's avatar
Sean C. Smith
3,818 posts
15 years ago
Sean C. Smith's avatar Sean C. Smith

Hi,

I’m using your other plugin Entry Categories with the following code

{exp:entry_cats entry_id="{entry_id}" backspace="2"}
    <a href="http://{path=home/C/}">{level1_category0_cat_name}</a> >
{/exp:entry_cats}

Which will output a list of subcategories with > separating them. However On the last category I don’t want the > to be there - how would I remove only the last instance here? Basically I’m looking to replicate the backspace parameter. Thank you for your time.

       
1 2 3

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.