[Gambas-user] pcre component 0.0.3 - working
Nelson Ferraz
nferraz at ...184...
Fri Oct 1 21:19:39 CEST 2004
Rob wrote:
>> IF MyStr MATCH "fox" THEN ...
>>Or even:
>> IF MyStr LIKE "fox" THEN ...
>
> It would replace 3 lines of code (DIM, then NEW, then
> checking the offset) with 1, but for most of my uses I need
> access to the submatches so I'd still have to explicitly create
> an object.
The MATCH (or LIKE) operator could set a few properties in the
background, so the code would be something like this:
IF MyStr MATCH "(\w+)" THEN
PRINT RegExp.SubMatch(0)
END
I don't know if this is an elegant solution but would be handy. :)
> I'd also like to write a
> Replace method that would be sort of like the s/from/to/g in
> perl, except returning a value rather than operating on the
> buffer directly.
I think it should operate directly on the variable; that's what we
usually want, isn't it?
It could return the number of substitutions, so we could write:
IF REPLACE(MyStr,"fox","dog") THEN
' 1 or more substitutions
...
ELSE
' zero substitutions
...
END
More information about the User
mailing list