Re: How do I use substrings in regular expressions?

2010-04-14 Thread Terry Vogelaar
Hi Michael,

I agree with Richard and want to thank you for the script. I don't really 
demand a regex; I just need to replace the SWF reference with the appropriate 
JPG. 

I used a regex because I often use GREP in BBEdit. But apparently the 
implementation in runrev is a bit different. It should be based on PCRE, and 
that supports this behavior. Might this be a little bug? Whatever the case, I 
am helped!

You noticed the ID was gone in the IMG tag with the JPG. I removed it because I 
didn't need it. But it's cool with me if it stays in. 

Terry

> Michael Kann wrote:
>> Here's a somewhat generic script to find any HTML element by its ID
>> and make the replacements you need. It doesn't use regex. I apologize.
> 
> No need to apologize. RegEx is convenient, but it's able to offer that 
> convenience usually at the price of performance.
> 
> It almost always takes more lines of code to do the same thing with 
> chunk expressions as one can do in RegEx, but is often much faster.
> 
> And when someone else writes the code, as you've done here, you get both 
> speed and convenience. :)
> 
> --
>  Richard Gaskin
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: How do I use substrings in regular expressions?

2010-04-14 Thread Richard Gaskin

Michael Kann wrote:
> Here's a somewhat generic script to find any HTML element by its ID
> and make the replacements you need. It doesn't use regex. I apologize.

No need to apologize. RegEx is convenient, but it's able to offer that 
convenience usually at the price of performance.


It almost always takes more lines of code to do the same thing with 
chunk expressions as one can do in RegEx, but is often much faster.


And when someone else writes the code, as you've done here, you get both 
speed and convenience. :)


--
 Richard Gaskin
 Fourth World
 Rev training and consulting: http://www.fourthworld.com
 Webzine for Rev developers: http://www.revjournal.com
 revJournal blog: http://revjournal.com/blog.irv

> 
> 
> on mouseUp
>
> put "ID4" into chosen_id
> put "ID=" into id_part_uno
> put quote&chosen_id"e into id_part_dos
> put id_part_uno & id_part_dos into id_target
> --
> put fld 1 into  v -- original data
> put numToChar(255) into z -- arbitrary item delimiter
> set the itemDelimiter to z
> --
> -- put a marker before and after the image elements
> -- to confine them to their own item
> --
> put " put ">" into item_stop
> replace item_start with z&item_start in v
> replace item_stop with item_stop&z in v
> --
> repeat for each item i in v
>
> if id_target is in i then
> put "flashblocks/editors/Mediablock.swf" into bad
> put "flashblocks/data/resize/home1_holder_txt_IDPLACE_mb.jpg" into good
> replace bad with good in i
> replace IDPLACE with chosen_id in i
> put i after h
> end if
>
> end repeat
> --
> -- remove the item separators
> --
> replace z with empty in h
> put h into fld 2 -- holds output
> end mouseUp
>

___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


Re: How do I use substrings in regular expressions?

2010-04-14 Thread Michael Kann
Terry, 

Here's a somewhat generic script to find any HTML element by its ID and make 
the replacements you need. It doesn't use regex. I apologize.


on mouseUp

put "ID4" into chosen_id
put "ID=" into id_part_uno
put quote&chosen_id"e into id_part_dos
put id_part_uno & id_part_dos into id_target
--
put fld 1 into  v -- original data
put numToChar(255) into z -- arbitrary item delimiter
set the itemDelimiter to z
--
-- put a marker before and after the image elements
-- to confine them to their own item
--
put "" into item_stop
replace item_start with z&item_start in v
replace item_stop with item_stop&z in v
--
repeat for each item i in v

if id_target is in i then
put "flashblocks/editors/Mediablock.swf" into bad
put "flashblocks/data/resize/home1_holder_txt_IDPLACE_mb.jpg" into good
replace bad with good in i
replace IDPLACE with chosen_id in i
put i after h
end if

end repeat
--
-- remove the item separators
--
replace z with empty in h
put h into fld 2 -- holds output
end mouseUp


I noticed that your jpg image doesn't have an ID attribute. In the above script 
the ID remains the same. That is probably a good idea since the ID is embedded 
in the jpg name and it would be confusing to have an ID attribute that was 
different. You'll need an ID to manipulate it with javascript (which I'm sure 
you know).


Hope this at least gives you something to think about.

Mike

--- On Tue, 4/13/10, Terry Vogelaar  wrote:

> From: Terry Vogelaar 
> Subject: How do I use substrings in regular expressions?
> To: use-revolution@lists.runrev.com
> Date: Tuesday, April 13, 2010, 1:55 PM
> I cannot get this regex to work:
> 
> put replacetext(textBlock,q(" ([^>]*) ID='" & idNumber & "' ([^>]*)>"),
> q("")) into
> textBlock
> 
> The purpose is to replace:
>  WIDTH="300" HEIGHT="100" ID="ID3" ALIGN="left" VSPACE="2"
> HSPACE="8">
> with:
>  SRC="flashblocks/data/resize/home1_holder_txt_ID3_mb.jpg"
> WIDTH="300" HEIGHT="100" ALIGN="left" VSPACE="2"
> HSPACE="8">
> 
> The \2 and \3 part should insert the substrings matching
> ([^>]*). This is working in BBEdit, but Rev gave me
> literally "\2 \3>": 
>  SRC="flashblocks/data/resize/home1_holder_txt_ID3_mb.jpg" \2
> \3>
> 
> I cannot use the normal replace command, because it should
> only work when the ID attribute is matched. 
> 
> Terry___
> use-revolution mailing list
> use-revolution@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage
> your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 


  
___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution


How do I use substrings in regular expressions?

2010-04-13 Thread Terry Vogelaar
I cannot get this regex to work:

put replacetext(textBlock,q("]*) ID='" & idNumber & "' 
([^>]*)>"), q("")) into textBlock

The purpose is to replace:

with:


The \2 and \3 part should insert the substrings matching ([^>]*). This is 
working in BBEdit, but Rev gave me literally "\2 \3>": 


I cannot use the normal replace command, because it should only work when the 
ID attribute is matched. 

Terry___
use-revolution mailing list
use-revolution@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution