Regular expressions in scheme? 
Author Message
 Regular expressions in scheme?

Hi Schemers,

I just got and installed scheme (scm and slib) and am looking
for a way to do regular expressions.  Is there a regexp package
for scheme?  A quick grep through slib got no hits.

Basically I will be doing a lot of text manipulation
(regexp substitution and matching, assoc arrays, lists) and am
contemplating a migration from perl to scheme, is this a good
step?

Here is a simple perl script, can someone post a simple scheme
equivalent?

# untested....
open(F, "<cats") || die "cats $!";
while(<F>) { chop; ($catid,$catname) = split; $CATS{$catid}=$catname;}
close(F);

open(F, "<junk") || die "junk $!";
while(<F>)
{
  ($catid,$rest) = split;
   $rest =~ s/$catid/$CATS{$catid}/g;
   print $rest;

Quote:
}

close(F);

Thanks,
-joe



Sat, 11 Jul 1998 03:00:00 GMT  
 Regular expressions in scheme?
Hi Schemers,

I just got and installed scheme (scm and slib) and am looking
for a way to do regular expressions.  Is there a regexp package
for scheme?  A quick grep through slib got no hits.

Basically I will be doing a lot of text manipulation
(regexp substitution and matching, assoc arrays, lists) and am
contemplating a migration from perl to scheme, is this a good
step?

Here is a simple perl script, can someone post a simple scheme
equivalent?

# untested....
open(F, "<cats") || die "cats $!";
while(<F>) { chop; ($catid,$catname) = split; $CATS{$catid}=$catname;}
close(F);

open(F, "<junk") || die "junk $!";
while(<F>)
{
  ($catid,$rest) = split;
   $rest =~ s/$catid/$CATS{$catid}/g;
   print $rest;

Quote:
}

close(F);

Thanks,
-joe



Sat, 11 Jul 1998 03:00:00 GMT  
 Regular expressions in scheme?

   Newsgroups: comp.lang.scheme

   I just got and installed scheme (scm and slib) and am looking
   for a way to do regular expressions.  Is there a regexp package
   for scheme?  A quick grep through slib got no hits.

   Basically I will be doing a lot of text manipulation
   (regexp substitution and matching, assoc arrays, lists) and am
   contemplating a migration from perl to scheme, is this a good
   step?

Scsh includes regexp matching support and other tools useful for
this kind of processing, such as an awk macro. To download the
manual or the entire system, go to

        http://www-swiss.ai.mit.edu/scsh/

        -Olin



Sun, 12 Jul 1998 03:00:00 GMT  
 Regular expressions in scheme?

   Hi Schemers,

   I just got and installed scheme (scm and slib) and am looking
   for a way to do regular expressions.  Is there a regexp package
   for scheme?  A quick grep through slib got no hits.

Yes, look in the documenation and makefiles that come with SCM.
There's already regexp support there, you just have to compile it in
(it's not added by default).  I've used it and it seems to work fine.

   Here is a simple perl script, can someone post a simple scheme
   equivalent?

I don't know perl, but in SCM, you have `regcomp' to compile the
regular expression, and `regmatch?' to test for a match.

(define r1 (regcomp "^-+ CUT -+"))
[...]
(if (regmatch? r1 line)
    (do-cool-stuff))

I think I have that right ...

   Thanks,
   -joe

Hope I helped.
--
Kevin K. Lewis               | My opinions may be unreasonable



Mon, 13 Jul 1998 03:00:00 GMT  
 Regular expressions in scheme?

I put together a modified  regular expression interface
for SCM-4e1 that lets you do searching, matching, splitting, and
editing.

If you want a copy of the code, send mail.

Don Bennett

From the README file:

(regcomp <pattern> [<flags>])

  Compile a regular expression.
  Return a compiled regular expression, or an integer error code
  suitable as an argument to regerror.

  <flags>     in regcomp is a string of option letters used to control
              the compilation of the regular expression. The letters may
              consist of:

        'n' - newlines won't be matched by . or hat lists; ( [^...] )
        'i' - ignore case.
  only when compiled with _GNU_SOURCE:
        '0' - allows dot to match a null character.
        'f' - enable GNU fastmaps.

(regerror <errno>)

  Returns a string describing the integer <errno> returned when
  regcomp fails.

(regexec <re> <string>)

  Returns #f or a vector of integers.  These integers are in doublets.
  The first of each doublet is the index of <string> of the start of the
  matching expression or sub-expression (delimited by parentheses in the
  pattern).  The last of each doublet is index of <string> of the end of
  that expression.  #f is returned if the string does not match.

(regmatch? <re> <string>)

  Returns #t if the <pattern> such that <regexp> = (regcomp <pattern>)
  matches <string> as a POSIX extended regular expressions.  Returns #f
  otherwise.

(regsearch  <re> <string> [<start> [<len>]])
(regsearchv <re> <string> [<start> [<len>]])
(regmatch   <re> <string> [<start> [<len>]])
(regmatchv  <re> <string> [<start> [<len>]])

  Regsearch searches for the pattern within the string.
  Regmatch anchors the pattern and begins matching it against string.
  Regsearch returns the character position where <re> starts, or
    #f if not found.
  Regmatch returns the number of characters matched, #f if not matched.
  Regsearchv and regmatchv return the match vector is returned if <re>
    is found, #f otherwise.

  <re>        may be either:
              a) a compiled regular expression returned by regcomp;
              b) a string representing a regular expression;
              c) a list of a string and a set of option letters.

  <string>    The string to be operated upon.

  <start>     The character position at which to begin the search
              or match. If absent, the default is zero.

              *** Compiled _GNU_SOURCE and using GNU libregex only: ***
              When searching, if <start> is negative, the absolute
              value of <start> will be used as the start location
              and reverse searching will be performed.

  <len>       The search is allowed to examine only the first <len>
              characters of <string>. If absent, the entire string
              may be examined.

(string-split  <re> <string>)
(string-splitv <re> <string>)

  String-split splits a string into substrings that are
  separated by <re>, returning a vector of substrings.

  String-splitv returns a vector of string positions that
  indicate where the substrings are located.

(string-edit  <re> <edit-spec> <string> [<count>])

  Returns the edited string.

  <edit-spec> Is a string used to replace occurances of <re>.
              Backquoted integers in the range of 1-9 may be used
              to insert subexpressions in <re>, as in sed.

  <count>     The number of substitutions for string-edit to perform.
              If #t, all occurances of <re> will be replaced.
              The default is to perform one substitution.

--
   Don Bennett



Sat, 18 Jul 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Regular Expression for scheme (really amiga gambit)

2. RELEASE: WIN32 port of SIOD (scheme dialect of lisp) now with regular expression capability

3. QUERY: regular expression package written in Scheme?

4. Regular expressions and environment vars in Scheme

5. RELEASE: WIN32 port of SIOD (scheme dialect of lisp) now with regular expression capability

6. regular expression matching in J ? (or APL)

7. Tgen, linear algebra, and regular expression package available

8. Regular Expressions

9. Regular Expression Matcher v1.1

10. apl and regular expressions

11. php like regular expressions in apl?

12. Support for regular expressions in APL?

 

 
Powered by phpBB® Forum Software