Regexps

Simon Marlow [email protected]
Wed, 11 Jul 2001 16:23:45 +0100


> ["1,0,0,0","","","","","","","","","","","","","","","","","",
> "","","","","","","","","","",""]
>=20
> ie the right answer, and 28 other empty answers.=20
>=20
> The documentation says
>=20
> "Note that there may be more components in the returned list than were
> in the pattern, and that any component which either matched the empty
> string or wasn't matched at all (because it was part of an=20
> optional part
> of the pattern), will be empty."
>=20
> Does this mean I had 28 matches with the empty string?

No, it means there are more components in the returned list than in your
original pattern, and you should ignore the extra ones.  This is because
GNU regex doesn't tell us how many components are actually returned, as
I recall.

> Why are they
> returned? Will I always have to filter all these null strings out of
> every result? Will the result I want always be first?

Yes, no(*), and yes.

(*) don't filter out the null strings, just strip the extra ones from
the tail of the returned list.  Remember that some of the components may
legitimately be empty, for example if one of the components in your
pattern was optional (eg. "a(bc)?d").

Cheers,
	Simon