EE: Find and Replace plugin

My first plugin for EE: Find & Replace. This post now provides a place for support for the Low Replace plugin.

Download and docs for Low Replace can be found in the Software section

February 1st 2005 | Add-Ons, ExpressionEngine | 122 comments

Comments

  1. 1 Joost February 1st 2005, 15:07

    Praat jij nou maar Nederlands.

  2. 2 Low February 1st 2005, 15:13

    @Joost: ‘t Is voor een internationaal publiek bedoeld, vandaar.

  3. 3 Joost February 1st 2005, 15:21

    Achzo :-)

  4. 4 Erwin Heiser October 11th 2006, 12:41

    Nice plugin, should come in handy somewhere.
    @joost: pipe down, laddy!

  5. 5 Alexo December 10th 2006, 03:56

    NIce plugin, just one question

    how to resplace [’ ] ?

    for example i have “Parkinson’s Disease” no to resplace with “Heart Disease”

    how can i do it ?

  6. 6 Low December 10th 2006, 11:33

    Alexo, you should probably make sure whether the single quote is converted to a html entity. Check the source code for this. You should probably use something like:

    {exp:replace find="Parkinson’s" replace="Heart"}

  7. 7 Alexo December 13th 2006, 20:18

    Hello there

    Thank you Low for this piece of code : ’ :-)

  8. 8 Magnus Wester February 12th 2007, 15:55

    Hi Low,
    I use your plug-in on my site. It removes the tags and control characters in the Summary field so I can use it in the Descriptions meta tag.
    Thanks a lot for the regular expressions support.
    Magnus

  9. 9 John Heasly February 14th 2007, 22:54

    I wasn’t able to get it to replace hard carriage returns with a space.

    Using:
    {exp:replace find=”(\\w)+
    (\\w+)” replace=”$1SPACE$2″ regex=”yes” multiple=”yes”}
    {/exp:replace}

    It found the hard returns but didn’t insert the space in the replace.

    i.e., with the text
    “Get rid of the hard return
    in this entry. And every other
    hard return too.”

    Result:
    “Get rid of the hard returnin this entry. And every otherhard return too.”

    And also the “find” would inexplicably skip some of the hard returns. But I’d be happy with getting the “replace” syntax right.

  10. 10 Magnus Wester February 15th 2007, 09:05

    John,
    i guess you could try working with the control characters directly instead, i.e.
    find=”/(\\r\\n|\\r|\\n)/” replace=”/SPACE/”
    (The above would support both the Windows, Macintosh and Unix end-of-line sequences; I don’t know if you need that but why not make it bullet-proof.)
    Multiple=”yes” means nothing with a regex so you can leave it out. The plug-in always replaces all strings that match your regex.
    Magnus

  11. 11 J Heasly February 15th 2007, 21:38

    Hey Magnus,

    Thanks for your post.

    Your suggested control characters method seems to work in the same hit-and-miss way as mine. The “\w+” pattern seems to skip words beginning with capital letters. Is this normal? And the hard carriage returns that are getting removed aren’t getting replaced with a space. And you were also right about not needing Multiple=”yes” in a regex.

    Here’s the pattern I used:
    {exp:replace find=”/(\\w+)\\r(\\w+)/” replace=”/$1SPACE$2/” regex=”yes”}

    Just curious: Why do you have a slash character after each open quote and before each close quote?

    John

  12. 12 Low February 16th 2007, 00:01

    John, I got this working with the following pattern: {exp:replace find="(\\r\\n|\\r|\\n)" replace="SPACE" regex="yes"}

    But, are you sure that this is what you want? Maybe there’s formatting being applied to your text, so that carriage returns are being converted to <br />’s, which are left alone by the plugin. Do you have a working example online you can link to?

  13. 13 John Heasly February 16th 2007, 03:55

    Hello Low,

    Your solution works about the same as mine or Magnus’. That is, it catches some of the line breaks/hard returns and misses others and fails to replace any that it finds with a space.

    What I’m doing is using the Moblog module to turn e-mails into entries. The e-mailed entries come with a few bad high-ASCII characters and many line breaks/hard returns that I’m trying to remove by running them through some regiex-capable filter such as yours. The first thing I’d like to do is get rid of the line breaks, then maybe worry about some of the odd characters.

    In my template, the field that I’m running through your filter has the Xhtml formatting option, but it doesn’t seem to make a difference if it’s on or off.

    Thanks in advance for any help you can offer!

  14. 14 Low February 16th 2007, 10:13

    John, can you try this one?

    {exp:replace find="\\s+" replace="SPACE" regex="yes"}

    That should replace any whitespace with one space. Also, if you can copy and paste your target text, you can try several regular expressions in this useful workbench.

  15. 15 Magnus Wester February 16th 2007, 10:31

    John,
    The slashes I use are just the normal regex delimiters, the same way you surround strings with quotes. You don’t need to use them since Low’s plugin neatly adds them for you if they’re missing. Sorry for any confusion.
    You have a complex data-related problem that may be beyond what can be expected of a simple find/replace utility. It would be fairly easy to build a “cleanser” plug-in for EE to do what you want.
    Otherwise, my next suggestion is that you simply reverse the pattern - have find/replace look for anything that isn’t in the allowed character set, and make that a space:

    find=”/[^\\w]/” replace=”SPACE”

    Just add all remaining characters you want to allow inside the square brackets. As usual, some special characters need to be prefixed by a backslash.

  16. 16 David March 2nd 2007, 12:22

    Hey Low, Trying to use your find and replace plugin to convert lastname, firstname into firstname lastname.

    The first code I used was

    find=”(\\w+), (\\w+)” replace=”\\2 \\1″ regex=”yes”

    Which appears to work with singles names, ie “Joiners, The” gets replaced with “The Joiners”

    However “Educated Animals, The” gets replaced with “Educated The Animals” (it should be “The Educated Animals”)

    I was under the impression that the + would find one or more. so I thought it would find one or more words before the ,

    I then tried (.+), to see if matching any character many times would work. It didn’t it gave the same result as above.

    Using the reWork site you linked above the (.+), did link the first two words into a group the (\w+), didn’t.

    Any ideas what I’m doing wrong?

  17. 17 David March 2nd 2007, 12:26

    Scrap that. The (.+) does work. I was changing the wrong instance of it to test. Doh!

    Thanks for the excellent plugin.

  18. 18 David March 2nd 2007, 12:42

    Aha. You thought I’d let you off then didn’t you. Well unfortunately not.

    Using (.+), (\w+) for some reason converts “¡Forward Russia!” into “Russia ¡Forward!”

    (If ¡ doesn’t convert its a Inverted Exclamation Mark)

    The reWork site and other regex utilities leave it alone. Am I doing something wrong or have I found a bug?

  19. 19 Low March 2nd 2007, 12:53

    Hi David. Try this on for size:

    find="([^,]+), (\\w+)" replace="$2 $1"

    That will look for anything but the comma in the first part. I think that should work.

  20. 20 David March 2nd 2007, 12:59

    Nope. Gives the same result. There’s no comma in this string so I’m confused as to why its matching it ¡Forward Russia! is correct and should be ignored by find and replace

  21. 21 Low March 2nd 2007, 13:18

    Strange. It works here. Can you point me to your example? Send me an email if it’s private.

  22. 22 David March 2nd 2007, 13:24

    Strange very strange. My Example You’ll have to login first. Its still closed Dev and if you want to look at the template its v4/numbers_inc

    Thanks in advance. I’ve probably done something stupid but I can’t see it

  23. 23 Low March 2nd 2007, 14:13

    David, I don’t seem to be able to access the v4 template group in your control panel. But I tested this code, which seemed to work:

    {exp:replace find="([^,]+), (.+)" replace="$2 $1" regex="yes"}{title}{/exp:replace}

    Note that I don’t use \w for the last part either. That’ll sort “Harvey, P.J.” out.

  24. 24 David March 2nd 2007, 14:25

    Ok. Very strange. The new regex fixes PJ Harvey (I hadn’t gotten around to spotting her yet) but forward Russia still doesn’t behave itself. I now get Russia! ¡Forward
    Huh, what’s going on?

    I created the v4 group after I created your member group. I’ve know fixed it so you can access it.

  25. 25 Low March 2nd 2007, 15:26

    I spotted it! You’ve actually got two Forward Russia entries in your bands section: “&#161;Forward, Russia!” and “Forward Russia!”. There’s your problem, right there. :)

  26. 26 David March 2nd 2007, 16:24

    hmmm. Well I deleted Forward Russia! and still get Russia! ¡Forward. Can I assume the special character is breaking something?

  27. 27 David March 2nd 2007, 16:56

    OK I don’t know what I did but its now working. I was just testing it out on a different bit of the page and it now works.

    Thanks for looking into this buddy.

  28. 28 Low March 2nd 2007, 17:00

    It works now, ’cause I removed the comma from the title, which was “&#161;Forward, Russia!” (sic). Note the comma in the middle. There’s the culprit. :)

  29. 29 David March 2nd 2007, 17:03

    *bleep* I never noticed that. You my friend are a genius.

  30. 30 Xacret.T May 10th 2007, 23:31

    Help me please.
    I have an image tag:
    /images/uploads/image/expressionengine.png
    and I need to get this:
    http://linka.ws/phpThumb/phpThumb.php?src=/images/uploads/image/expressionengine.png&w=300

    I’ve spend several hours trying understand regular expressions but it doesn’t helped… I’m not able to write this expression

  31. 31 David May 11th 2007, 09:39

    Hey Xacret. You don’t really need to use regex to do this.

    Say the only bit of the url that changes is the filename all you need to do is

    FIND /images/
    REPLACE phpThumb/phpThumb.php?src/images/

    That will leave the rest of your link unchanged but give you the phpthumb bit too.

  32. 32 Xacret.T May 11th 2007, 10:36

    Yes, I did it with simple search and replace.
    The link in my first comment was parsed.
    I too have to add a parameter to the end of src: &w=300
    I have an image tag:
    /images/uploads/image/expressionengine.png
    and I need to get this:
    phpThumb.src=”/images/uploads/image/expressionengine.png&w=300″

  33. 33 billg June 17th 2007, 16:27

    Hi,
    Does it work with custom fields? I’m trying to use it to replace a SPACE with a “+” in a Technorati tag that I’ve implemented as a custom field.

    Like this:

    {exp:replace find=”SPACE” replace=”+”}{Technorati-1}{/exp:replace}

    I.e., I enter something like “Word Word” as the tag, and need to replace the space with a plus sign so the link itself actually contains “word+word”.

    Thanks.

  34. 34 billg June 17th 2007, 18:47

    Oops. It was my mistake. Works just fine. Apologies.

  35. 35 AdamG July 4th 2007, 08:08

    Is there a way to capitalise using this plugin?

    I have this:

    {exp:replace find=”(\\w+)-(\\w+)” replace=”\\1SPACE/SPACE\\2″ regex=”yes”}{segment_2}{/exp:replace}

    Which turns this:
    “climate-change”
    Into this:
    “climate change”

    I would also like to capitalise the first letter of every word, so I can get:
    “Climate Change”

    Is this possible? Thanks very much!

  36. 36 Low July 4th 2007, 09:48

    Adam, you can use CSS to do just that: text-transform:capitalize;

  37. 37 AdamG July 5th 2007, 03:49

    Thanks Low!
    Unfortunately I need to use this in the <title>, so CSS won’t work.

  38. 38 Erwin Heiser August 23rd 2007, 17:45

    Hi, would it be possible to put in multiple regular expressions and then say multiple=”yes”?
    Something like this:
    {exp:replace find=”regex1|regex2|regex3″ replace=”X” multiple=”yes”}
    text you want processed
    {/exp:replace}
    I’m using the plugin to filter out some of the crap TinyMCE injects into its HTML…

  39. 39 Stanislav Majerski September 15th 2007, 19:29

    Thank you for this plugin. Just used it a project. Very handy and it made me finally to start learning RegEx.

  40. 40 Riob Q September 16th 2007, 23:30

    I’d like to use this on an email addresses:

    first.last@website.com

    so that it shows it like this: first last

    Essentially, replaces the dot with a space (I know this is possible) and then takes the @ and everything after that and replaces it with nothing. I know the first is easy. Second possible?

  41. 41 Riob Q September 16th 2007, 23:32

    Just fyi - the above post left out my email example. I basically want to take any email address and take out everything at the @ symbol and past it.

    Also, if there are dots in the first part to replace with a space which I know is possible.

  42. 42 Victor September 17th 2007, 05:10

    Yeah good day: i was just trying out some things and noticed that when you use:
    {exp:replace find="[br]" replace="<BR>"}
    something [br] more thing
    {/exp:replace}

    This does not work, any ideas is the [ ] is causing the problem ?

  43. 43 Low September 19th 2007, 09:37

    Victor, the [] shouldn’t be a problem. Are you using any other plugins in combination with this one?

  44. 44 Quena October 26th 2007, 15:09

    Thanks, all, for a lively and helpful discussion?

    To anybody who (like Magnus) is using this plugin to convert a custom field to the META description tag: Care to share your code, including the list of “find”s? I’m wondering how to catch all entities, special characters and HTML, without continually updating my templates as users discover new problems to throw at me.

    If you prefer to post your answer in the EE forums, clicking on my name will take you into the EE forum thread where I posted this question. If you post here, please let me know if you DON’T want me to cross-post it there.

    Thanks in advance!

  45. 45 Magnus Wester October 26th 2007, 16:23

    Hi Quena,
    Whatever I can contribute to solve your problem I added to your thread in the EE forums.
    Good luck!

  46. 46 Mark Bowen April 29th 2008, 15:06

    Hiya,

    Just wanted to say thanks for this plugin. I actually downloaded it yonks ago but came to using it today on something and realised that I hadn’t said thank you so here goes…

    … Thank you!!

    Keep up all the great work, it is very much appreciated.

    Best wishes,

    Mark

  47. 47 Tomelloso June 26th 2008, 20:52

    Hi, nice plugin. I trued this and work fine for me. Thanks and keep up good work mate.

  48. 48 Luke Stevens September 18th 2008, 07:42

    Hey Low, the replace plugin is a given on any EE installation I work on, so thanks for releasing it :)

    Just one random question - is there any way to replace a pipe | in a chunk of text? It’s not hugely important but I’m working with aggregated blog headlines that are something like:
    Some blog title | Blog Posts | My Cool Blog
    … which are fine for titles, but they look pretty ugly in my design, so I wouldn’t mind tweaking them a bit ;) If you have any suggestions it would be much appreciated, thanks!

  49. 49 Low September 21st 2008, 17:56

    @Luke Stevens: if you’re not using multiple="yes" or regex="yes", then replacing a pipe should work just as any other character.

  50. 50 Luke Stevens September 22nd 2008, 15:31

    Oh great, thanks for letting me know :)

  51. 51 MS November 10th 2008, 04:36

    Hi Low,
    I have been trying every possible combination of things to make this work. I am using your plugin in ee with a blog posting audio files from hipcast. Hipcast sends this:

    <iframe src=”http://www.hipcast.com/playweb?audioid=P85964305c5f19f6fd2df7dffdf1b1c73bFB+RFREYmN2&buffer=5&fc=FFFFFF&pc=CCFF33&kc=FFCC33&bc=FFFFFF&brand=1&player=ap21″ height=”20″ width=”246″ frameborder=”0″ scrolling=”no”> </iframe>

    Essentially i need to convert out the opening and closing carots and my most recent attempt i tried the following

    {exp:replace find=“<iframe;|scrolling=’no’>|</iframe>â€? replace=“<iframe|scrolling=’o'>|</iframe>â€? multiple=”yes”}

    I also tried just replacing using <| >

    Can you point me in the right direction?

  52. 52 Low November 10th 2008, 15:42

    @MS: I’m sorry, but I don’t understand what it is you’re trying to accomplish. Do you need to replace the opening and closing html-brackets with html-entities? In that case, you’d probably need something like find="<|>" replace="&lt;|&gt;" multiple="yes".

  53. 53 MS November 10th 2008, 19:02

    I am so sorry i didnt check that post carefully after submit

    this is what hipcast sends

    <br / >
    & l t ;iframe src=”http://www.hipcast.com/playweb?audioid=P85964305c5f19f6fd2df7dffdf1b1c73bFB+RFREYmN2&buffer=5&fc=FFFFFF&pc=CCFF33&kc=FFCC33&bc=FFFFFF&brand=1&player=ap21″ height=”20″ width=”246″ frameborder=”0″ scrolling=”no” & g t; & l t ;/ iframe & g t ;

    i added spaces so it wouldn’t convert.

    This is the code (one of many attempts) I used (again spaces added)

    {exp:replace find=“& l t ;| & g t ;â€? replace=“<|>â€? multiple=”yes”}

  54. 54 Ian November 20th 2008, 18:33

    Low said above: “@Luke Stevens: if you’re not using multiple=”yes” or regex=”yes”, then replacing a pipe should work just as any other character.”

    What if you need to replace a pipe character and use multiple=”yes”?

  55. 55 Low November 20th 2008, 19:01

    @Ian: with the current version (1.3), you can’t. I’ll need to update plugin to allow for such a functionality.

  56. 56 rh2600 November 23rd 2008, 10:23

    Works great :) but it doesn’t render out when inside the magpie plugin…

    {exp:magpie url=”http://www.google.com?search={exp:replace find=”SPACE” replace=”+;”}{title}{/exp:replace}” limit=”1″ refresh=”720″}

    any ideas?

  57. 57 Low November 23rd 2008, 12:11

    @rh2600: you can’t use a plugin as input for another plugin like that. You’ll have to find a way to do the replacing before you use it as a parameter. By using php on input, for example.

  58. 58 Beebs December 9th 2008, 00:02

    Thanks a lot for great plugin. A trully time-saver!

  59. 59 Nelly March 12th 2009, 03:45

    First of all, thanks for this great plugin. It helped me with a big problem I had with paths for a site’s mobile version.
    I think it’s necessary to escape any “/” in the regular expressions, and I didn’t see that in the documentation.

  60. 60 Albert March 12th 2009, 16:02

    Hi,
    thank you for this cool plugin. One question though: How do I replace a ” with nothing? I tried to escape it as \” but it didn´t work.
    I checked the thread in the EE forum, but couldn´t find anything.

    Thanks
    awa

  61. 61 Low March 12th 2009, 16:05

    Hey awa. Try this: {exp:replace find="QUOTE"} ... {/exp:replace}

  62. 62 Albert March 12th 2009, 16:36

    Dank u wel! That was a quick reply all is working now
    awa

  63. 63 Daemon March 13th 2009, 15:57

    Hi! Picture this. Simply text like “drums guitar piano” needs to be replaced with drums guitar piano.. So the word has to replaced with a hyperlink that forms a filename based on it’s orgin name.

    {exp:replace find=”\\w+” replace=”<a href=”[(the value of \w+]+.mp3″> [(the value of \w+]</a>” regex=”yes”}
    drums guitar piano
    {/exp:replace}
    How far I am off? Kind regards, D’R

  64. 64 Low March 16th 2009, 14:11

    Hi Daemon. That’ll be something like find="(\\w+)" replace="<a href='$1.mp3'>$1</a>" regex="yes", so you’re not far off.

  65. 65 Vishnu March 17th 2009, 20:06

    I have to replace as below and it works only few occurances, So correct me if this is wrong of the doing it.
    exp:replace find=”’|–|â€Â?|“|Â|â€â€?|…” replace=”‘|-|QUOTE|QUOTE|SPACE|SPACE-” multiple =”yes”}{body}{/exp:replace}

    Thanks,
    VishnuP

  66. 66 Low March 17th 2009, 20:13

    VishnuP, check the html source — you might need to look for html entities instead of the special characters.

  67. 67 Peter August 1st 2009, 17:53

    This is great! I have one question..
    Is there any way to pass in an EE tag variable? I need to replace a certain word with a weblog field URL.

    Peter

  68. 68 Peter August 1st 2009, 17:58

    Screw my above question, it seems to work. Another question:
    Can you parse multiple regexs with multiple outputs?

    Peter

  69. 69 Fat Rick September 8th 2009, 22:44

    Worked great. Real time saver.

  70. 70 rob q September 8th 2009, 23:32

    I’m doing a find a replace on the word “and” and replacing it with “&” but sometimes it picks the “and” from the middle of a word. Is there a way to ensure if only replaces “and” if there is a space before and after it so some words like “Expand” don’t look like “Exp&” afteward?

  71. 71 RobbieGod October 7th 2009, 22:52

    Is it possible to put the text I have modified into a variable?

    I want to modify a string and then place its new value into a EE variable so i can use it throughout the webpage.

    Please let me know.

  72. 72 Low October 7th 2009, 22:55

    Rob q: You’d have to use a regular expression, I guess.

    Robbie: No, that’s not possible with this plugin.

  73. 73 RobbieGod October 8th 2009, 03:22

    Any chance you feel like adding a new parameter called var ? This way I could do my search and replace and then whatever I put in the var parameter would be the name of the variable the modified text gets placed into.

    I’m not sure how difficult that would be to program…

  74. 74 Low October 10th 2009, 17:43

    Robbie: I’ll put in on a list somewhere, but don’t hold your breath. :)

  75. 75 RobbieGod October 14th 2009, 02:08

    ok, i won’t hold my breath but it will be very cool feature and the first of its kind. None of the search and replace string modifiers for EE do that. It would be one step closer to not having to use PHP at all in my page and that I think would be great.

  76. 76 Low October 14th 2009, 15:56

    Robbie, can you give me an example of how it should work? Cause at the moment, I cannot get a clear idea of what you want. You want “the text you have modified” in a variable. As far as I can tell, this could mean several things.

    1. Not using regex, you want whatever you put in the find parameter as a variable. In the first example, that variable would hold the value ‘you’. This is the text you have modified, but since you already need that value for the plugin, making it a variable seems pointless. You could use dynamically assigned variables for that.

    2. Using regex, you want whatever matches the pattern in the find parameter as a variable. This isn’t possible, because, like in example #6, it can be several things.

    3. You want the full original text (everything between the tag pair before replacing) as a variable. But this will cause recursion problems, as you need to use the variable inside the tag pair as well.

  77. 77 RobbieGod October 15th 2009, 03:55

    Certainly.

    Here is what i would like it do…I don’t remember your exact syntax so I’ll just sort sketch out the steps in plain english.

    I have a string. my goal is modify the string. Say I want to use ltrim to remove the http://www.flickr.com/1298234230/ from this Flickr URL.
    I use your plugin using ltrim. The resulting value is “1298234230″. I’d like that resulting value to be placed into a variable.

    The benefits of this would be:
    1. I can organize my code in the page in such a way to have all of my values defined at the beginning of the page and use the variable throughout the page.
    2. I can accomplish this with PHP, but then i have to turn on PHP on my template and I try to avoid that. This would help me do that.
    3. Variable are simply cleaner and easier for me to read. So I’d like something to modify a string and put the result value into a variable. That would be soooo freakin cool!

    The main instance I was thinking about was Flickr. I was consuming a Flickr feed with Magpie. I was using PHP to ltrim and rtrim the URL so I could get the UserID number. I couldn’t figure out how to do that with your plugin, but i could do it with PHP.

    I think this would make all the difference in the world.

  78. 78 RobbieGod October 15th 2009, 03:57

    As far as how maybe it could work, i’d love to see this:


    {exp:replace find="you" replace="we" var="Whatever_I_Want_Here"}
    text you want processed
    {/exp:replace}

    {Whatever_I_Want_Here} would equal "text we want processed"

    Does that sound cool?

  79. 79 Christian November 12th 2009, 16:45

    Hi Low, Thanks for the plugin. I am sitting over it and can’t get something working though. I use anchor tags in local nav .EE creates trailing slashes when I use the href=”{path=’/something’}” after something, which breaks the link. How can I use the plugin to replace the / with nothing. Thanks

  80. 80 Low November 12th 2009, 16:59

    @Christian: you’ll have to use a regular expression. Something like:

    {exp:replace find="\\/$" regex="yes"}{path="something"}{/exp:replace}#yourhash

    That will get rid of the trailing slash.

  81. 81 Sean November 18th 2009, 10:10

    Low,

    I”m trying to get this to replace underscores with a space but it’s not working. I’m using your last segment trick but want to remove the underscores - unfortunately the way things are set up I can’t do this inside a weblog:entries tag which means no option for {title}

    Here is the code I’m using now: (I tried it with and without the multiple=”yes” option but no dice)


    {exp:replace find=“_”  replace=“SPACE” }{last_segment}{exp:replace} 

  82. 82 Low November 18th 2009, 10:14

    Hey Sean. Your closing tag isn’t closing: {/exp:replace}
    Also, make sure you’re not using curly brackets in your code.

  83. 83 Sean November 18th 2009, 10:16

    Thank-you. Feel really stupid about that mistake.

  84. 84 Janson November 24th 2009, 19:17

    Piggy-backing on what Erwin asked, is there a way to pass in multiple find/replace regexes? preg_replace() does that by passing in arrays of regex find/replace pairs, but not sure how that’d work with your plugin. Any ideas?

  85. 85 Rob Q. December 28th 2009, 21:59

    Hi, I’m using a simple webform in a template to submit a small string of text to the address bar as part of query string (?q=TEXT) like this “www.websitedomain.com/?q=TEXT”. From there I’m using an EE url segment (segement_1) tag to pull in that text from the address bar after the form submits in parts of the page. But, I’m trying to strip out part of the url segment that is the query characters (?q=) and leave just the submitted text. But using the find and replace plugin seems to choke on the inclusion of a “?” and it won’t strip anything out if that’s included. Can you suggest a method to use to strip out the inclusion of a question mark (?q=) when processing with the plugin?

    Thanks!
    Rob

  86. 86 Rob Q. December 29th 2009, 03:45

    Sorry, I may have incorrectly misidentified the problem. I think it’s the nature of using EE url segments. I don’t think they pull in content when started with “#” “%” or “?” in them. Just a guess…

  87. 87 Low December 30th 2009, 23:14

    Rob, if a url contains a “?”, then anything after that is part of the Query String. If a url contains a “#”, then anything after that usually refers to an anchor somewhere on that page. If a url contains a “%”, then it’s usually url-encoded ( for a space, for example). In any of these cases (apart from the percentage sign), anything after is not part of the EE segments, and therefore not accessible via the {segment_x} variables.

  88. 88 Ryan February 2nd 2010, 06:15

    When using this with the twitter_timeline plugin, how should the plugin tags be nested?

    I am using your example from the ee forum to replace @username links. Here’s what I’ve tried:

    {exp:low_replace find=”@([_a-zA-Z0-9]+)” replace=”@<a href=’http://twitter.com/$1′>$1</a>” regex=”yes”}
    {exp:twitter_timeline type=”user” …

    This seems to suppress any output from the twitter_timeline plugin. Am I making an obvious error?

  89. 89 Low February 2nd 2010, 10:46

    Ryan, that code seems to work for me, both in EE 1.6.8 and 2.0.1. Make sure you use {exp:replace…} for 1.6.x and {exp:low_replace…} for 2.x and check closing tags, quotes etc.

  90. 90 Ryan February 3rd 2010, 02:42

    Thank you for your response, Low. I did a test and confirmed that your plugin is working fine. (Turns out it’s the twitter_timeline modification I am trying to make that is causing the problem).

  91. 91 Ryan February 3rd 2010, 03:06

    I spoke too soon :P

    Links are working in twitter_timeline, and @username links are also working, but these two things are not working together. Here is my code. It still seems to me I might be breaking some nesting rules. Can I have a tag pair within your ‘low’ tag pair? (I am using ee2.0)

    {exp:low_replace find=”@([_a-zA-Z0-9]+)” replace=”@<a href=’http://twitter.com/$1′>$1</a>” regex=”yes”}
    {exp:twitter_timeline type=”user” user=”****” password=”****” limit=”5″ refresh=”15″}
    <div class=”tweet”>
    {status_relative_date}
    {text}
    </div>
    {/exp:twitter_timeline}
    {/exp:low_replace}

  92. 92 Low February 3rd 2010, 10:34

    Ryan, the nesting is fine. In fact, I just tested your code in my EE2.0.1pb01, build 20100121 (not the trial or freelance version) and it works just fine. Are there any other add-ons that might interfere?

  93. 93 Ryan February 4th 2010, 03:41

    I am stumped. The only plugins I have installed are this one, and the twitter timeline (in addition to the Magpie RSS and XML default plugins). I appreciate your help. I will need to revisit this in a few weeks.

  94. 94 Chad Clark February 10th 2010, 06:10

    Hi Low,

    I am using this plugin to find and replace text being output via Javascript for a Flowplayer-based playlist.

    If a person enters a single quote into the text field (which has to be non-xhtml), the playlist breaks.

    Is there a way with Find and Replace to find a single quote and replace with ’? I know it is possible for double quotes via QUOTE.

  95. 95 Low February 10th 2010, 21:27

    Chad, you should be able to use something like this:

    {exp:replace find="'" replace="&apos;"}

  96. 96 Paradise February 11th 2010, 08:10

    Hi Low,

    can I do this with, what is done with LG’s replace, with your replace.
    I cant figure it out :-(


    {exp:lg_replace:haystack needles="{cf_images backspace="1"}image_{row_count}|{/cf_images}"}

    {cf_images}
    {exp:lg_replace:replacement needle="image_{row_count}"}
    {exp:imgsizer:size src="{image}" width="{image_size}" alt="{image_caption}" class="{image_align}"}
    {/exp:lg_replace:replacement}
    {/cf_images}

    {/exp:lg_replace:haystack}

  97. 97 Low February 11th 2010, 08:51

    Paradise, LG Replace works differently than Low Replace. I’m afraid that what you’re trying to do cannot be achieved with Low Replace.

  98. 98 Paradise February 11th 2010, 09:16

    Hmpf you allready answered. Just found out where the difference is after trying the whole time to get this LG thing running. The only thing yours and LG’s have common is the name “replace”. LG’s is not a renaming thing its more a putting here putting there thing :-).

    Sorry for waisting your time. EE is sometimes “trial and error” and allways learning by doing…

  99. 99 Brittany February 15th 2010, 18:54

    Hi Low, thanks for great plugin! Trying to get rid of some html. I want to completely delete a div. My original html is <div class=”imageright style=”width:xx”>TEXT</div> I want to delete the entire string.

    Here’s what I’m attampting:

    {exp:replace find=”<div class=”imageright”.*?</div>” replace=”" regex=”yes” }

    Seems like when it gets to the ” before imageright, it stops the replacement.

    I’m a newbie at regex — sorry, I’m trying to learn! Any suggestions? Thanks!

  100. 100 Low February 16th 2010, 13:17

    Brittany, if you need to replace a double quote, use the string QUOTE instead of ".

  101. 101 Brittany February 16th 2010, 17:16

    Hey Low — thanks for the feedback! I’d tried that based on your examples in the docs, but I just can’t get it to work. Here’s my code:


    {exp:replace find=“<div class=QUOTEimagerightQUOTE.*?</div>” replace=“” regex=“yes” }{starter_text}{/exp:replace} 

    As you can see, the results are here: http://uvamagazine.org/mobile/article/uva_student_dies_in_haiti_earthquake/

    no text is appearing in the body!

  102. 102 Nagib February 22nd 2010, 22:03

    Having an issue with Mars Edit/Metaweblog & EE 1.6.8. The code for the youtube gets corrupted.

    Specifically: ‘<’ and ‘>’ get converted to ‘<’ and ‘>’ respectively.

    So if you enter <object>blah blah and save it to EE, it immediately comes back as <object>blah blah

    I’m trying to use low_replace to solve this, but I’m wondering if I need a regex?

    {exp:low_replace find=”<|>” replace= “<|>” multiple=”yes”}
    {summary}
    {body} –> eg:<object width=”425″ height=”344″>
    {extended}
    {/exp:low_replace}

    Sorry.. not great with this - just trying to figure it out.

    Thanks,

  103. 103 Low February 22nd 2010, 23:09

    Nagib, please read the docs carefully. On the top it says you should use the tag {exp:replace} — without low_ — if you’re using EE 1.x, which includes 1.6.8.

  104. 104 Nagib February 23rd 2010, 00:01

    HI Low,

    Apologies.. I did do that - but it still makes no difference. Does this have to be done as a regex? Eg: The text that has < and > is contained with a variable such as {summary} and EE converts this to (&lessthan;) “& l t ;” I need it to stay as ‘ < ‘

  105. 105 Low February 23rd 2010, 00:06

    Nagib, go to CP Home › Admin › Weblog Administration › Weblog Management › Edit Weblog Preferences and set the value “Default HTML formatting in weblog entries” to “Allow ALL HTML”.

    That should probably do it, and you don’t even need the plugin.

  106. 106 Nagib February 23rd 2010, 00:26

    Hi Low,

    Already did that. When I enter this in EE direct it is fine, when I do it through Mars Edit it screws up and coverts the “<” to “l t ;”. On EE people mentioned your tool as the best way around it. That’s why I came here. I just need to find a way to prevent EE changing this when it receives a blog post from MarsEdit/Blogo/Ecto anything. I can’t believe I’m the only one experiencing the issue.

  107. 107 Brittany February 24th 2010, 17:03

    Hey Low — I’m pulling my hair out with this issue and I’m wondering if you have any ideas for me. I tried your suggestion:

    {exp:replace find="<div class=QUOTEimagerightQUOTE.*?div>" replace="" regex="yes"}{starter_text}{/exp:replace}

    But still nothing shows! (as can be seen here: As you can see, the results are here: http://uvamagazine.org/mobile/article/uva_student_dies_in_haiti_earthquake/)

    when I replace the QUOTE with actual quotation marks ” then everything up until the first quotation mark is removed, but it stops there.

    (Sorry to repost, I’m desperate!)

  108. 108 Low February 24th 2010, 17:11

    Brittany, I’ve edited your comment above, ’cause the quotes around the parameter values were curly quotes instead of regular ones. You can actually try and copy/paste the above code and see if that works — maybe the curly quotes are in your template as well.

  109. 109 Brittany March 31st 2010, 22:11

    Low - thanks for all your help. It was functioning perfectly until I added a parameter.


    {exp:replace find=“<div class=QUOTEimagerightQUOTE.*?div>|<div class=QUOTEimagecenterQUOTE.*?div>|<div class=QUOTEarticlesideQUOTE.*?div>|<div class=QUOTEimageleftQUOTE.*?div>” replace=“” regex=“yes”}{article_body}{/exp:replace} 

    All function EXCEPT for div class=”articleside” which remains in the text. You can see it here: http://uvamagazine.org/mobile/article/this_old_academical_village
    (the div is around the paragraph titled “handyman’s delight”

    I’ve checked for stupid stuff like curly quotes… I hope it’s not something like that again!

    Thanks for your help, Low!!

  110. 110 Brittany March 31st 2010, 22:12

    I don’t think my code posted correctly (the dang quotes look curly, but i know they aren’t!) Let’s try again…
    {exp:replace find="<div class=QUOTEimagerightQUOTE.*?div>|<div class=QUOTEimagecenterQUOTE.*?div>|<div class=QUOTEarticlesideQUOTE.*?div>|<div class=QUOTEimageleftQUOTE.*?div>" replace="" regex="yes"}{article_body}{/exp:replace}

  111. 111 Brittany April 8th 2010, 18:08

    Hi Low,

    I had my IT guy (who knows reg ex) look at this and he could not get it to perform (specifically the “articleside” variable). Any ideas?

  112. 112 Low April 9th 2010, 08:26

    Brittany, maybe you could try something like this:

    {exp:replace find="<div class=QUOTE(imageright|imagecenter|articleside|imageleft)QUOTE.*?div>" regex="yes"}

    Untested, but should work, I think.

  113. 113 Brittany April 12th 2010, 16:22

    Thanks for getting back to me! But no luck, that didn’t work. I”m using find and replace in conjunction with html_strip, but I removed the html_strip and still it wasn’t working. Just doesn’t like that “articleside” div. Any other ideas would be appreciated.

  114. 114 QB Marketing April 16th 2010, 16:50

    I think this plugin might help me but I’m not certain. i have a client that has the registered trademark symbol throughout their site, in custom fields, and even in titles. Can this plugin be used the swap the special character ® with <sup>®</sup> so the thing is superscripted everywhere it appears in the site? And so the plugin tags would have to be at the start and end of each template, correct?

  115. 115 Brendan April 24th 2010, 09:42

    Low, trying to replace a ‘/’ (forward slash) in a string with an ‘_’ (underscore) and tried your suggestion as per your Nov 12th post to Christian, but can’t seem to get it working. Example string could have slash anywhere:

    ‘4659/GD’ or ‘4641/GD/SL’

    Hope you can help.

    Thanks
    Brendan

  116. 116 Brendan April 24th 2010, 09:45

    Ignore me, too many days coding in a row and forget to close the tag pair.

  117. 117 David April 27th 2010, 23:07

    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.

  118. 118 Low April 28th 2010, 10:08

    David, you could use an embed:variable or path.php variables for that. Remember that using the “title1|title2|title3″ syntax, you also need to use multiple=”yes”. But if you want to replace those with links, you’ll probably need to use a regular expression.

    QB Marketing: Most likely, the ® character is changed into a html entity by EE. That means you’ll have to look at the source to see what the exact code is, then use that as your parameter. You’re right as to where to place the tags.

  119. 119 Stephen McIver July 16th 2010, 00:21

    Hi Low,

    I’m using EE 1.6.9 and the latest version of this plugin, 1.3.

    I have a segment that contains a year (2009 or 2010), and I’m trying to output the segment in a h4 as 2010 if the segment is 2009, and 2011 if the segment is 2010 (don’t ask!).

    I’ve used this plugin before without any issues, but for some reason, it keeps outputting the value as 2011 no matter whether the segment is 2009 or 2010. Here’s my code:

    {exp:replace find=”2009|2010″ replace=”2010|2011″ multiple=”yes”}{segment_4}{/exp:replace}

    Any ideas on this at all?

    Thanks,

    Stephen

  120. 120 Shane McCarthy August 7th 2010, 11:45

    Hi Low,
    is there anyway to replace just the number 0 with ‘None’ and not affect multiples 10 20 30 etc?

    Great plugin, has helped me a load!

  121. 121 Low August 7th 2010, 12:10

    Stephen, try swapping the values, so find="2010|2009" replace="2011|2010". The replacement doesn’t happen instantaneously, but one after the other. Therefore, if a 2009 is replaced with 2010, and then the next replacement kicks in, it’ll replace 2010 with 2011. Turning the order around will keep that from happening.

    Shane, you’ll need a regex for that. If you’re wrapping it right around the variable, try something like this:

    {exp:replace find="^0$" replace="None" regex="yes"}{some_var}{/exp:replace}

  122. 122 Shane McCarthy August 7th 2010, 12:14

    Wasn’t expecting such a quick response!
    Thanks Low, really appreciate it!
    Shane

Leave a comment



Some html (a, em, strong, etc) allowed.
Email won’t be displayed and takes care of your Gravatar.