Regex.Replace

  • Thread starter Thread starter cj
  • Start date Start date
C

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
 
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?
 
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.
 
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.

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.
 
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.
 
Back
Top