regexp:first_match

Erik Pearson erikp@REDACTED
Mon Nov 19 20:05:18 CET 2001


I think the documentation could be made much clearer.

My experience is that regexp:match selects the longest
match when the match can start at *different* positions
in the string.  Keep in mind, a match at any given
position is *always* the longest match.

In Niels' case,

2> regexp:first_match("<DATE>22-03-03</DATE>","<.+>").

There are two matches in the string:

{match,1,21}
{match,15,7}

But because of greediness there is no match
for the first 6 characters; they're consumed
in the first match case.

To see the difference with match and first_match,
try adding an optional pattern to differentiate
the longest from the first match.

1> regexp:match("12123", "123?").
{match,3,3}
2> regexp:first_match("12123", "123?").
{match,1,2}

--erikp--

-----Original Message-----
From: Bengt Kleberg [mailto:eleberg@REDACTED]
Subject: Re: regexp:first_match 

According to the documentation
regexp:match()
will get thet longest match, exactly as you state.

regexp:first_match()
is documented as only matching the first match (which should be the one
Niels 
Christensen wanted).

bengt



More information about the erlang-questions mailing list