[Sc-devel] regexp support revisited :)

Florian Schmidt mista.tapas at gmx.net
Sat Nov 3 17:21:43 PST 2007


On Saturday 03 November 2007, Dan Stowell wrote:
> Hi -
>
> I'm currently ill so not doing any coding at the moment, so I can't
> test, sorry. But this occurs to me: instead of returning the length of
> the matched text, could you return the text itself?
>
> e.g.
> "sesame seeds".findRegExp("s.*e")
> [[0, "se"], [2, "same"], [7, "see"]]
>
> This would give more flexibility (because of course it's easy to find
> the lengths from the above result).

Sure. I thought about this, too, for the same reason. But i was too lazy to 
look at how to create strings ;)

Will do..

BTW: 

"sesame seeds".findRegexp("s.*e")
[ [ 0, 10 ] ]

It will find only the first occurence of the expression in the source string. 
The following entries in the Array are the subexpression matches (those 
things in ordinary brackets "()"]..

"aaaafoobaaaarxxxxx".findRegexp("(fo*)(ba*)",3)
[ [ 1, 8 ], [ 1, 3 ], [ 4, 5 ] ]

First subexpression matched is "(fo*)" matched by "foo" at pos 1 [relative to 
offset 3] and length 3. Next subexpression match is "(ba*)" matched 
by "baaaa" at pos 4 [relative to offset] and length 5. I guess one could 
write a utility method on top that spits out [0] of the result.

String.findRegexpNoSubs
{
	arg expression, int offset = 0;
	var result;

	result = this.findRegexp(expression, offset);

	if (result.size != 0, 
		{
			result[0];
		},
			nil;
		}	
	);
}

or something like that..

You probably had a findAllRegexp in mind, which i still have to decide whether 
to implement it on top of findRegexp or to create a new primitive for...


Regards,
Flo

-- 
Palimm Palimm!
http://tapas.affenbande.org


More information about the Sc-devel mailing list