FW: Way to do RegEx substring replacements? Solution (looks good)

Jim Ault JimAultWins at yahoo.com
Sun Mar 5 18:28:35 EST 2006


Done off list, but I thought this might be helpful to someone out there.
Jim Ault

------ Forwarded Message
From: Jim Ault <JimAultWins at yahoo.com>
Date: Sun, 05 Mar 2006 14:56:21 -0800
To: Jim Witte <jswitte at bloomington.in.us>
Conversation: Way to do RegEx substring replacements?
Subject: Re: Way to do RegEx substring replacements?

On 3/5/06 1:06 PM, "Jim Witte" <jswitte at bloomington.in.us> wrote:

> 
> The blocks that I have are lines of assembly in the form of
> 0025FE2F mov r1, [r2, lsl #2]   | FE32FDB - ..D.
> 
> I want to get rid of everything after the last bit of the assembly
> code, and isolate the address of the line.  In TextWrangler, I could
> use a RegEx/replace similar to the I listed above to get rid of the
> 'end part' after the '|' character, and then use a search for \s*\r
> and replace with \r to get rid of the trailing spaces.  I've got
> everything working now in RunRev, except getting rid of the trailing
> spaces, while I'll do in TextWrangler.
Hey, Jim (nice name)

Test my solution quickly by doing two things:

Make a new mainstack, then set the script to the following => dbl click

----- start copy -------------------------
on mouseDoubleUp
  put "0025FE2F mov r1, [r2, lsl #2]            | FE32FDB - ..D" into tempp
  put the ticks into startt
  put 5000 into lineCnt
  repeat lineCnt
    put tempp & cr after block
  end repeat
  put the ticks - startt into elapsed
  answer "Done building " &lineCnt & " lines  " && elapsed && "ticks"
  
  put the ticks into startt
  
  get replaceText( block,"\|","MMMM")
  get replaceText(it,"].*MMMM .*","]")
  put the ticks - startt into elapsed

  put it -- result is in the msg box

  answer "Done replace 2x in " &lineCnt & " lines  " && elapsed && "ticks"

--my answer = 44 ticks
end mouseDoubleUp

-------- end copy -----------------

My result on a Mac G5 dual 2.0 was 0 ticks to create 5000 lines, and 44
ticks to do the replaceText.

All I was able to figure out is that something about the line of text
confuses the RegEx routine so that selection of the correct text is
thwarted.  The double replace

Hope this works for you.
Of course, you could use anything in place of the "MMMM" string to remain
unique.  It is just a place holder.

Jim Ault
Las Vegas

------ End of Forwarded Message





More information about the Use-livecode mailing list