RegEx Help

Sivakatirswami katir at hindu.org
Tue Aug 6 19:06:01 EDT 2002


[was re:  Setting Itemdelimiter to multiple character string]

Ken Ray wrote:

> I would suggest using regular expressions instead of item delimiters for
> this. MC 2.4.3's support for PCRE is awesome. If you need some help on this,
> let me know.

Well I solved this by swopping out the string for a "|" character,
processing the items and then swopping the string back in. Turned out to be
very simple. But, your generous offer cannot be turned down as PCRE is
indeed "awesome" (our young wizard in the next room back flipped over to my
desk just now to gush about what he had just done with grep in BBEdit...
So... RegEx is in the air!) and I would like to see if you have a better
method. Here the script, it would be interesting to see if a grep string
could be made that would pick up all 5 formats.
~~~~~~~~~~~~~~~~~~~~~~~~~~~
## Summary of formats from Chamundi's list
## Goal is: wrap all subsequent text with Quark italic tags

#1: Text string ending with ": See " and one or more words/phrases
#2: Tab followed by "See also " and one or more words/phrases
#3: Text string ending with ", see " and one or more words/phrases
#4: Text string ending with " (see also ", one or more
words/phrases,end-paren
#5: Text string ending with ". See also " and one or more words/phrases

on mouseup
  set the casesensitive to true
  put fld "tText" into tOldFile
  
## change itemdelimiter now for all routines
  
  set the itemDelimiter to "|"
  
  ## Now read each line of the data
  ## and process the different five formats if found in that line
  
  repeat for each line x in tOldFile
    
    ## Format 1 -- Text string ending with ": See " and one or more
words/phrases
    
    if x contains ": See" then
      replace ": See" with "|" in x
      put "<I>" before item 2 of x
      put "<$>" after item 2 of x
      replace "|" with ": See" in x
    end if
    
    
    ## Format 2 : Tab followed by "See also " and one or more words/phrases
    
    put tab & "See also"  into tabbed_entry
    
    if x contains tabbed_entry then
      replace "See also" with "|" in x
      put "<I>" before item 2 of x
      put "<$>" after item 2 of x
      replace "|" with "See also" in x
      
    end if
    
    #3: Text string ending with ", see " and one or more words/phrases
    
    if x contains ", see "  then
      replace ", see " with "|" in x
      put "<I>" before item 2 of x
      put "<$>" after item 2 of x
      replace "|" with ", see " in x
    end if
    
    
    #4: Text string ending with " (see also ", one or more
words/phrases,end-paren
    
    if x contains " (see also "  then
      replace " (see also " with "|" in x
      put "<I>" before item 2 of x
      put "<$>" before last char of item 2 of x ## don't italicize right
parenthesis mark
      replace "|" with " (see also " in x
    end if
    
    #5: Text string ending with ". See also " and one or more words/phrases
    
    if x contains ". See also "  then
      replace ". See also " with "|" in x
      put "<I>" before item 2 of x
      put "<$>" after item 2 of x
      replace "|" with ". See also " in x
    end if
    
    ## post the data to the new variable with a return
    
    put x & cr after tNewFile
  end repeat

## clean up garbage, double spaces, double commas, dangling commas etc
  
  put cleanUpText(tNewFile) into tNewFile
  
  ## Post the variable to a GUI field
  
  if the hilite of btn "Preserve Data" = "true" then
    put tNewFile into fld "output"
    set the hilite of btn "Output" to true
    set the vis of fld "output" to true
  else
    put empty into fld tText
    wait 20 ticks
    put tNewFile into fld ttext
  end if
  
end mouseup





Om shanti,
Hinduism Today

Sivakatirswami
Editor's Assistant/Production Manager
katir at hindu.org 
www.HinduismToday.com, www.HimalayanAcademy.com,
www.Gurudeva.org, www.hindu.org

Read The Master Course Lesson of the Day at
http://www.gurudeva.org/lesson.shtml




More information about the metacard mailing list