[Gambas-user] Regexp Error at compile time: 'Bad Character Constant String'
Benoît Minisini
gambas at ...1...
Sat Oct 26 15:20:11 CEST 2013
Le 26/10/2013 13:10, Alain Baudrez a écrit :
> 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:
>
> ' 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?
>
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
More information about the User
mailing list