Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2012-02-28 21:08:27

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: rah_replace - Search and replace

towndock wrote:

Example: If cat were on the page four times, I need the 2nd and 4th instances to become dog.

Mmm… I have a vision of a combo of rvm_counter, txp:variable and if_variable and at least two instances of rah_replace… and maybe some smd_query and smd_if to finish it off… ;)

Offline

#26 2012-02-28 21:37:30

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

Ugh, breaking these bubbles. I’m a meanie.

Els wrote:

I have a vision of a combo of rvm_counter, txp:variable and if_variable and at least two instances of rah_replace…

Sorry, but unfortunately, not going to work. You can’t effect rah_replace’s search-and-replace routine in shape or any form. You will need sub-string replacing that has movable pointer, which isn’t what rah_replace does. It always replaces all occurrences, and not even words, i.e. catwomen becomes dogwomen.

Only way you could even theory make it work with rah_replace is to create sub-strings prior to running rah_replace by splitting each words and then joining the results back together. In which point rah_repleace becomes obsolete as you already have individual words to do 1on1 replacing (no search needed).

and maybe some smd_query and smd_if to finish it off… ;)

I don’t see none of those, as it stands, doing it either. Smd_query has no relation to the case at all. It builds DB queries and that is it.

Last edited by Gocom (2012-02-28 21:39:48)

Offline

#27 2012-02-28 21:57:29

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: rah_replace - Search and replace

Gocom wrote:

Sorry, but unfortunately, not going to work.

Haha, not a surprise :) I didn’t think very hard about it. Just curious, is something like this complete nonsense?

<txp:variable name="dogs" value="0" />
<txp:rah_replace from="dog<!-- 2 -->,dog<!-- 4 -->,dog<!-- 6 -->" to="cat,cat,cat">
   <txp:rah_replace from="dog" to='dog<!-- <txp:adi_calc name="dogs" add="1" display="1" /> -->'>
      text with dogs goes here
   </txp:rah_replace>
</txp:rah_replace>

To answer my own question, yes, I expect it is ;)

Offline

#28 2012-02-28 22:26:06

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

Els wrote:

Just curious, is something like this complete nonsense?

Yes.

Offline

#29 2012-02-28 22:28:39

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: rah_replace - Search and replace

Gocom wrote:

Yes.

Thank you. I can let go now ;)

Offline

#30 2012-02-28 23:18:47

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 308
Website

Re: rah_replace - Search and replace

Thank you all for having a try at this. I might just have to let it go too…

Offline

#31 2012-07-12 03:18:25

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_replace - Search and replace

Rah_replace v0.4 is out. Brings some performance optimizations.

More info and downloads

Offline

#32 2012-07-12 10:01:40

gaekwad
Multi-hyphenate
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 3,509
GitHub

Re: rah_replace - Search and replace

Thanks, Jukka – looks great!

Offline

#33 2013-03-29 15:48:26

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

Re: rah_replace - Search and replace

Thanks Jukka for this plugin.

I’m doing using rha_replace for parsing <txp:site_slogan /> with <br /> and <small></small>
This is the code I use <txp:rah_replace from="|,__,/__" to="<br />,<small>,</small"><txp:site_slogan /></txp:rah_replace> and this is the value of field Fusce ultricies ultricies nunc|Maecenas in ligula|__Aenean tincidunt adipiscing nibh/__

I expect to get this code Fusce ultricies ultricies nunc<br />Maecenas in ligula<br /><small>Aenean tincidunt adipiscing nibh</small> but I obtain Fusce ultricies ultricies nunc<br />Maecenas in ligula<br /><small>Aenean tincidunt adipiscing nibh<small></small></small> width double small code.

How I can resolve this issue?

Offline

#34 2013-03-29 16:53:06

etc
Developer
Registered: 2010-11-11
Posts: 4,252
Website GitHub

Re: rah_replace - Search and replace

Marco, I guess what you really get is Fusce ultricies ultricies nunc<br />Maecenas in ligula<br /><small>Aenean tincidunt adipiscing nibh/<small>, but the browser corrects this invalid markup. Try to change the order:

<txp:rah_replace from="|,/__,__" to="<br />,</small>,<small>"><txp:site_slogan /></txp:rah_replace>

Edit: Uli has the last word :)

Last edited by etc (2013-03-29 17:02:14)

Offline

#35 2013-03-29 16:54:15

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,238

Re: rah_replace - Search and replace

Marco, maybe just a forum typo in your tag: </small">. Shall the apostrophe really be there?
Secondly, try another order in your search pattern, __ is contained in /__ hence it might take action prematurely: from="|,/__,__" to="<br />,</small>,<small>"

Edit: Oleg was faster :)

Last edited by uli (2013-03-29 16:55:04)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#36 2013-04-01 06:24:18

MarcoK
Plugin Author
From: Como
Registered: 2006-10-17
Posts: 248
Website

Re: rah_replace - Search and replace

Thanks guys, works perfectly!!

Offline

Board footer

Powered by FluxBB