How do I use substrings in regular expressions?
Michael Kann
mikekann at yahoo.com
Wed Apr 14 09:42:38 EDT 2010
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 "<IMG SRC" into item_start
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 <tvogelaar at de-mare.nl> wrote:
> From: Terry Vogelaar <tvogelaar at de-mare.nl>
> Subject: How do I use substrings in regular expressions?
> To: use-revolution at lists.runrev.com
> Date: Tuesday, April 13, 2010, 1:55 PM
> I cannot get this regex to work:
>
> put replacetext(textBlock,q("<IMG SRC='([^']*)'
> ([^>]*) ID='" & idNumber & "' ([^>]*)>"),
> q("<IMG SRC='" & newPath & "' \2 \3>")) into
> textBlock
>
> The purpose is to replace:
> <IMG SRC="flashblocks/editors/Mediablock.swf"
> WIDTH="300" HEIGHT="100" ID="ID3" ALIGN="left" VSPACE="2"
> HSPACE="8">
> with:
> <IMG
> 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>":
> <IMG
> 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 at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage
> your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list