Regular Expressions in SenseTalk?

Good morning, All!

For fun (yeah, I know I don't have much of a life...:)) I'm writing a little utility that I can point at a bunch of scripts and generate todo lists based on a tag. The format of the todo is pretty standard:
//TODO <initials> <task>

The initials can have 0, 2, or 3 characters. I can easily do a regEx in another language, but I was wondering what I could do in ST to handle this. Right now, my script is rather brute force and assumes 3 characters for the initials. I would like to keep some of this parsing for other things that I have in mind.


  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Is something like this what you had in mind? Generally, any time you think you need regular expressions, a SenseTalk chunk expression (words in this case) will do what you need.

    Copy this into a new script and run it:
    //TODO dps Ask the user for the actual file here instead
    put the script of me into testScript
    repeat with each line of testScript
    	if the first word of it is not "//TODO" then next repeat
    	//TODO af This could be simpler if initials were required
    	put word 2 of it into initials
    	//TODO Problem here if first word of task is short!
    	if the length of initials is between 0 and 3 then
    		put words 3 to last of it into todo
    		put words 2 to last of it into todo
    		put empty into initials
    	end if
    	//TODO notice that we can create assignments on the fly
    	insert todo into the (initials) of assignments
    end repeat
    //TODO af Clean this up to work the way you want
    repeat with each initials of the keys of assignments
    	put "Assignments for " & (if initials is empty then "Anybody" else initials) & ":"
    	put assignments.(initials) joined by return
    	put -- empty line
    end repeat
    The fact that initials may be omitted will cause some problems with this approach. Did you have something in mind to identify a todo item without initials that starts with a 2- or 3-letter word?
  • Doug--

    I had forgotten about chunking by the word. I was trying to do something dumb with characters. I'm making this for our framework, so I can force users to put in their initials. :D .

    I'll have to get my notes back out from your talk :oops:

    Thanks for your help.

  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Sure. It doesn't hurt to review the chapter on Chunk Expressions now and then -- there's a lot that they can do.

    One of the things that's valuable about words in this case is that they will ignore leading white space. Notice that my script said "if the first word of it is not "//TODO" then...". I thought about saying "if it does not begin with "//TODO" then..." but that wouldn't have worked on TODO comments in indented sections of code, since they begin with spaces or tabs before the comment. One popular quick hack is to remove all leading and trailing spaces from an expression by saying "the first to last words of foo".
Sign In or Register to comment.