Erlang/OTP Forums

Author Message

<  User Contributions  ~  Regexp BIFs

ivaradi
Posted: Tue Aug 01, 2006 6:02 am Reply with quote
Joined: 01 Aug 2006 Posts: 2
I have implemented two BIFs for regular expression matching based on the Perl Compatible Regular Expressions (PCRE) library (http://www.pcre.org).

The interface is the following:

  • re:compile([RegExp]) -> [RegExpC]

    RegExp = string()
    RegExpC = term()

    It pre-compiles the given regular expressions so that using them would be faster later on.

  • re:grep(String, [RegExp]) -> [MatchItem]

    String = string()
    RegExp = string() | term()
    MatchItem = no_match | {int(Begin),int(End),[string(SubMatch)]} | {error,{string(ErrorStr),int(ErrorChar)}}

    It tries to match one or more regular expressions with the given string. RegExp can be either a regular expression as a string or a pre-compiled regexp as returned by re:compile. There is one MatchItem for each regular expressions, i.e. only the first match is returned if there are more than one matches. In case of a match, the indexes are 0-based and End points to the first character after the end of the match. The list of SubMatches contains the substrings matched by subpatterns.


To compile an emulator with the BIFs you need the two files attached to this post (besides the PCRE library, of course):

  • erl_bif_re.c: the imlementation of the BIFs. Put it into erts/emulator/beam.
  • re_patch.txt: a patch containing the other modifications needed: additions to the emulator's Makefile and the registration of the BIFs in bif.tab. This patch is relative to the parent directory of the OTP top-level source directory. (The funny suffix is due to the forum software refusing suffixes such as .patch or .diff.)


The files were created and tested with OTP R11B-0, though other versions might work as well.



erl_bif_re.c
 Description:
The implementation of the BIFs.

Download
 Filename:  erl_bif_re.c
 Filesize:  8.48 KB
 Downloaded:  1460 Time(s)


re_patch.txt
 Description:
Patch for other necessary modifications.

Download
 Filename:  re_patch.txt
 Filesize:  942 Bytes
 Downloaded:  1342 Time(s)

View user's profile Send private message Yahoo Messenger MSN Messenger ICQ Number

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum