RegEx Help

Sivakatirswami katir at hindu.org
Wed Aug 7 15:21:01 EDT 2002


on 08-07-2002 06:06 AM,"Ken Ray" <kray at sonsothunder.com> wrote:

Fabulous indeed! This will be VERY helpful for me to study out for future
text processing, which we do a lot of here. Thanks!
> 
> Here you go... it assumes that each line will end either with the "see
> [also]" reference (in the case of #1, #2, #3 and #5) or will end the line
> with the "see [also]" reference and a close parentheses (in the case of #4).
> 
> ----------------------------------
> on mouseUp
> local c1,c2,c3,c4
> put "" into tNewFile
> repeat for each line tLine in fld "tText"
>   put true into foundIt
>   if matchText(tLine,"(see also|see) (.*?)[\)]?$") then
>     -- ends in paren, keep it
>     get matchChunk(tLine,"(see also|see) (.*?)[\)]?$",c1,c2,c3,c4)
>   else
>     put false into foundIt
>   end if
>   if foundIt then
>     put (char 1 to (c3-1) of tLine) & "<I>" & (char c3 to c4 of tLine) & \
>       "<$>" & char (c4+1) to length(tLine) of tLine & cr after tNewFile
>   else
>     put "no match" & cr after tNewFile -- just in case
>   end if
> end repeat
> 
> -- clean up and rest of code here
> end mouseUp
> ----------------------------------
> Basically it looks for "see also" or "see", followed by a space and then
> grabs all text after that until it reaches the end of the text (indicated by
> the $ at the end of the regex), optionally followed by 0 or more close
> parentheses (indicated by the [\)]? in the regex).
> 
> Ain't PCRE great!  :-)
> 
> Enjoy!


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




More information about the metacard mailing list