[Gambas-user] Regexpr appears not to be working

John Harrold budgieboy52 at ...1601...
Sun Nov 30 22:49:28 CET 2008


Thanks Benoit

Oops! Silly mistake easily done, even more easily overlooked - I must have
read that line dozens of times and didn't spot the mistake.
Just shows how useful another persons eyes are.  Thanks again.

Budgieboy

2008/11/30 Benoit Minisini <gambas at ...1...>

> On dimanche 30 novembre 2008, John Harrold wrote:
> > Hi all
> > I am experimenting with the PCRE class to understand more about regular
> > expressions and Gambas in general
> >
> > I have created a form with two textboxes, one for text input the other
> for
> > the regular expression text to test against.
> > There are a number of labels for displaying results returned from the
> call
> > to Regexp.
> >
> > Below is the commented code for the change event for the input
> > textbox:txtInput.
> >
> > The issue I have is with the line marked ***.
> > By looking at the PCRE class documentation it seems that the line should
> > return a string.
> >
> > *PCRE Documentation on .SubMatches*
> > *RegexpSubmatches (gb.pcre)*
> > * .RegexpSubmatches contains the submatches returned from a
> > Regexp<http://gambasdoc.org/help/comp/gb.pcre/regexp?v3>match. You
> > access it with the SubMatches
> > property <http://gambasdoc.org/help/def/property?v3> of the Regexp
> class. *
> >
> > * Each member of a .RegexpSubmatches collection simply contains the text
> of
> > the corresponding submatch. For example, with a subject of "quick brown
> > fox" and a pattern of "brown (\S+)", SubMatches[0] would contain "fox". *
> > It does, however, complain with the following message:
> >
> > *Type mismatch: Wanted Number, Date or String, got .regexprSubMatches
> > instead.
> > *
> > The message seems to me to suggest that an array of .RegexpSubMatches is
> > being returned instead.
> > I have tried to read this returned array into a variety of arrays (string
> > and Object) but it always returns the above message.
> >
> > If I comment out the line I get no errors and the call to Regex returns
> > Regex.Text, Regex.Offset and Regex.SubMatches.Count correctly.
> >
> > Am I understanding the way to use the Regexpr correctly or have I made a
> > fundamental mistake somewhere?
> > Could it be a bug?
> >
> > Budgieboy
> >
> > *Code for input textbox:*
> >
> > *PUBLIC SUB txtInput_Change()
> >   DIM Regex AS Regexp
> >
> >     IF bCleared = TRUE THEN   'Flag to prevent error if try to send empty
> > string to Regex
> >       bCleared = FALSE
> >
> >     ELSE
> >       IF txtInput.Text = "" THEN 'We have empty input textbox, usually
> from
> > delete/backspace
> >         txtInput.BackColor = Color.RGB(255, 165, 204)
> >         RETURN
> >       ENDIF
> >       Regex = NEW Regexp(txtInput.Text, txtRegex.Text)  'Call Regexpr
> >
> >       lblResult.Caption = Regex.Text
> >       lblMatch.Caption = Regex.SubMatches.Count
> >       lblOffset.Caption = Regex.Offset
> >
> >       'This line below causes error:
> >       'Type mismatch: Wanted Number, Date or String, got
> .regexprSubMatches
> > instead
> > ***   IF Regex.SubMatches > 0 THEN lblSubMatches.Caption =
> > Regex.SubMatches[0].Text
>
> --> IF Regex.SubMatches.Count > 0 THEN ...
>
> --
> Benoit Minisini
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list