How do I use substrings in regular expressions?

Richard Gaskin ambassador at fourthworld.com
Wed Apr 14 09:51:42 EDT 2010


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&quote 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
 >




More information about the use-livecode mailing list