Hi,
I'm using the regexp package from Allegro CL and I couldn'd managed to
use the grouping syntax within a regular expression. Here is a sample
of the Allegro's documentation.
CL-USER: (match-regexp ".*" "foobarbaz")
T
"foobarbaz"
CL-USER: (match-regexp "foo\(.*\)baz "foobarbaz" :return :string)
NIL
The `:return :string' means that the content of all each grouping
constructs should be returned as multiple sub-strings. Anyway, it
doesn't seems to match my string anymore. I was expecting the function
to return something like:
T
"bar"
Here a sample of the Allegro documentation about the grouping syntax:
\(x\) This grouping syntax matches whatever x matches, and at the
same time remembers what x matches. There can be up to 9 groups
defined in a regular expression string. Each group is given a number
from 1 to 9 based on the order in which they appear in the pattern
string. When the match is made, the value of each group can be
returned by the match-regexp function.
--
Frederic Brunel
Software Engineer
In-Fusio - Mobile Game Connections
Frederic Brunel <···············@in-fusio.com> writes:
> Hi,
>
> I'm using the regexp package from Allegro CL and I couldn'd managed to
> use the grouping syntax within a regular expression. Here is a sample
> of the Allegro's documentation.
>
> CL-USER: (match-regexp ".*" "foobarbaz")
> T
> "foobarbaz"
>
> CL-USER: (match-regexp "foo\(.*\)baz "foobarbaz" :return :string)
> NIL
CL-USER(17): (match-regexp "foo\\(.*\\)baz" "foobarbaz" :return :string)
T
"foobarbaz"
"bar"
CL-USER(18):
Extra backslashes seem to do the trick.
From http://www.franz.com/support/documentation/6.2/doc/regexp.htm:
When typing a regular expression in Lisp source code keep in
mind that in order to represent a backslash in a string
constant you need two backslashes. The Lisp reader reads
"foo\+" as "foo+", when what you probably wanted was "foo\\+"
(where you are putting a backslash in front of the + to remove
its special meaning so you could match the string foo+.)
--
chr
···@sli.uio.no (Christian Nyb�) writes:
> CL-USER(17): (match-regexp "foo\\(.*\\)baz" "foobarbaz" :return :string)
> T
> "foobarbaz"
> "bar"
> CL-USER(18):
>
> Extra backslashes seem to do the trick.
Thanx for your answer, I've missed this information from the
documentation.
--
Frederic Brunel
Software Engineer
In-Fusio - Mobile Game Connections