Autore Topic: Errore Regexp in fase di compilazione: 'Bad Character Constant String'  (Letto 357 volte)

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.723
  • Ne mors quidem nos iunget
    • Mostra profilo
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.
"
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »