regular expressions in Prolog

John Benson <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Organization bensonsystems
Message-ID <[email protected]>
After a little investigation, I found this Prolog code to match regular
expressions:

    match_regex(Regex, String, Result) :-
         send(Regex, match, String),
         findall(W, (between(1,9, Z),
                 get(Regex, register_value, String, Z, name, W)),
             Result), !.
     
    amatchesregexb(Astring, Bregex, Result) :-
       use_module(library(pce)),
       setup_call_cleanup(new(Binternalregex, regex(Bregex)),
                   match_regex(Binternalregex, Astring, Result),
                   free(Binternalregex)).

 However, when I used it I got the following results:

    130 ?- amatchesregexb('ab12cd', '.*([0-9]+).*', Result).
    Result = ['2'].
     
    131 ?- amatchesregexb('ab12cd', '[^0-9]*([0-9]+).*', Result).
    Result = ['12'].
     
    132 ?-


*I expected the first example capture **([0-9]+) to cap**ture '12', but
it only captured '2'.*

I had to add [^0-9] infront of the numeric capture to successfully
capture both digits '12'.

I'm a Prolog newbie, and don'tunderstand the code that I copied.

Can anyone tell me what is wrong about it?
**

-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.