Home All Groups Group Topic Archive Search About
Author
19 Apr 2006 6:50 PM
cj
I just ran across this in the VB help.  Sounds perfect.  Only they don't
tell me what namespace must be imported to use regex.  I guess that's
the problem cause I pasted this into a test program and it tell me Regex
  is not declared.

Function CleanInput(ByVal strIn As String) As String
    ' Replace invalid characters with empty strings.
    Return Regex.Replace(strIn, "[^\w\.@-]", "")
End Function

Author
19 Apr 2006 7:56 PM
cj
The help says, "CleanInput returns a string after stripping out all
nonalphanumeric characters except @, - (a dash), and . (a period)."

I also don't get what the \w\ stands for.  I get [^.@-] mean anything
but the 3 characters following the ^.  I'd assume \w\ means any
alphanumeric character but I don't see that in the documentation on
regular expressions.  Can anyone shed any light on this?


cj wrote:
Show quoteHide quote
> I just ran across this in the VB help.  Sounds perfect.  Only they don't
> tell me what namespace must be imported to use regex.  I guess that's
> the problem cause I pasted this into a test program and it tell me Regex
>  is not declared.
>
> Function CleanInput(ByVal strIn As String) As String
>    ' Replace invalid characters with empty strings.
>    Return Regex.Replace(strIn, "[^\w\.@-]", "")
> End Function
Author
20 Apr 2006 7:21 AM
Gary Chang[MSFT]
Hi,

>The help says, "CleanInput returns a string after stripping
>out all nonalphanumeric characters except @, - (a dash),
>and . (a period)."

The help is alright. The [^\w\.@-] should be parsed into [^\w], [^\.],
[^@], and [^-] seperately. The '\w' matches the same as '[A-Za-z0-9_]'.

Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
20 Apr 2006 12:34 PM
cj
Thanks Gary,

Your explanation is really good.  I had looked up Regular Expressions in
VB help and it gave me a long list but \w was not in the list.  I've
been doing some web searches to learn more.  VB help is not very helpful
to me any more.


Gary Chang[MSFT] wrote:
Show quoteHide quote
> Hi,
>
>> The help says, "CleanInput returns a string after stripping
>> out all nonalphanumeric characters except @, - (a dash),
>> and . (a period)."
>
> The help is alright. The [^\w\.@-] should be parsed into [^\w], [^\.],
> [^@], and [^-] seperately. The '\w' matches the same as '[A-Za-z0-9_]'.
>
> Thanks!
>
> Best regards,
>
> Gary Chang
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
Author
21 Apr 2006 2:19 AM
Gary Chang[MSFT]
You are very welcome, I am glad to discuss this problem with you. :)

Have a nice weekend!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
19 Apr 2006 8:23 PM
cj
system.Text.RegularExpressions.Regex.Replace

cj wrote:
Show quoteHide quote
> I just ran across this in the VB help.  Sounds perfect.  Only they don't
> tell me what namespace must be imported to use regex.  I guess that's
> the problem cause I pasted this into a test program and it tell me Regex
>  is not declared.
>
> Function CleanInput(ByVal strIn As String) As String
>    ' Replace invalid characters with empty strings.
>    Return Regex.Replace(strIn, "[^\w\.@-]", "")
> End Function