Gambas-it

Gambas3 => Programmazione => Topic aperto da: vuott - 26 Ottobre 2013, 21:15:43

Titolo: Errore Regexp in fase di compilazione: 'Bad Character Constant String'
Inserito da: vuott - 26 Ottobre 2013, 21:15:43
Riporto questa discussione apparsa nella M.L. ufficiale:


" I would like to check the validity of an email using RegExp. gb.pcre has been added to the project.

This is the code that I use to validate an email:

Codice: gambas [Seleziona]

 ' Gambas class file
 Private sRegExp As Regexp

 Public Sub btnCheck_Click()

 ' RegEx pattern is taken from http://gambasdoc.org/help/comp/gb.pcre/regexp
    sRegExp = New Regexp(txtEmail.Text, "(?i)\b[a-z0-9._%\-]+@[a-z0-9._%\-]+\.[A-Z]{2,4}\b")

    If sRegExp.Offset = -1 Then Return

    Message.Info("Result: " &  sRegExp.Text)

End


I receive a 'Bad Character Constant String' on "(?i)\b[a-z0-9._%\-]+@[a-z0-9._%\-]+\.[A-Z]{2,4}\b"
at the first occurrence of the [ and its matching ] at compile time.
Using "\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" as regex pattern, I have the Bad Character Constant String
on the [ and ] surrounding the A-Z at the end of the string.

 It is my first go on using Regular Expressions. Is this a bug? or am I doing something wrong here?

Alain Baudrez
"


" The "\" character must be quoted in Gambas strings,
i.e. you must write two "\" so that the gb.pcre component receives one.

--
BenoƮt Minisini
"


" OK.

The doc must be adapted then, because I took it directly from
http://gambasdoc.org/help/comp/gb.pcre/regexp?v3

A.J.
"