RegEx Help

Ken Ray kray at sonsothunder.com
Wed Aug 7 13:14:00 EDT 2002


>     if matchText(tLine,"(see also|see) (.*?)[\)]?$") then

BTW, for those starting to get into regEx, the reason the matchText line
above says "(see also|see)" instead of ("see|see also") is that it attempts
to match each of these options in sequential order, so "(see|see also)" will
always match "see" (since "see" is in "see also") and would act just as if
you'd done this:

    matchText(tLine,"see (.*?)[\)]?$")

Doing it in reverse - "(see also|see)" - will cause it to try and match "see
also" *first* before it tries to match "see".

Just FYI...

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/


>       -- 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!
>
> Ken Ray
> Sons of Thunder Software
> Email: kray at sonsothunder.com
> Web Site: http://www.sonsothunder.com/
>
>
> ----- Original Message -----
> From: "Sivakatirswami" <katir at hindu.org>
> To: <metacard at lists.runrev.com>
> Sent: Tuesday, August 06, 2002 6:04 PM
> Subject: RegEx Help
>
>
> > [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
> >
> > _______________________________________________
> > metacard mailing list
> > metacard at lists.runrev.com
> > http://lists.runrev.com/mailman/listinfo/metacard
> >
>
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
>




More information about the metacard mailing list