[Gambas-user] Regular Expressions :: Error with gb.pcre component

Benoît Minisini gambas at ...1...
Wed Apr 25 19:35:05 CEST 2012


Le 25/04/2012 18:58, Daniel Quintero a écrit :
>     Hello, I have an error in this line of code when I use the \s constant
> in the pattern:
>
> re = New Regexp(sText, "<span\s([^>]*)>")
>
>     If I use "<span([^>]*)>" (Without the \s) I have no error.
>
>     The error occurs when I press the F5 function key to execute the program.
>
>     This is the error text:
>
>   This application has raised an unexpected
> error and must abort.
>
> [11] Unknown symbol 'Editor' in class 'FForm'.
> Project.CompileError.2072
>
>
> And this is the complete code:
>
>
> Public Sub Button1_Click()
>    Dim re As Regexp
>    Dim sText As String = TextArea1.Text
>    Dim matches As New String[]
>    Dim i As Integer
>
>    ' Error with de \s constant in the pattern
>    re = New Regexp(sText, "<span\s([^>]*)>")
>    Do While re.offset>= 0 And sText<>  ""
>      matches.push(re.text)
>      If Len(sText)>  Len(re.text) Then
>        sText = Mid(sText, re.offset + Len(re.text) + 1)
>      Else
>        sText = ""
>      End If
>      If sText<>  "" Then re.exec(sText)
>    Loop
>
>    For i = 0 To matches.Max
>      Print matches[i]
>    Next
>
> End
>
>      I have attached the project to more clarity.
>
>     Thanks.
>
> *_________________________*
> *Lic. Daniel Quintero Rojas*
> http://www.dquinter.com.mx
> http://futbol.dquinter.com.mx
> http://twitter.com/#!/dquinteror
>
> *¡Saludos desde México!________**
>
> *
>

This is a bug in the compiler and in your code.

Do you use the last revision? If not, just fix your regular expression 
by quoting the '\' with another '\' (because '\' is both the quoting 
character in Gambas string and in regular expressions!)

Regards,

-- 
Benoît Minisini




More information about the User mailing list