|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Regex.ReplaceI 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? 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 Hi,
>The help says, "CleanInput returns a string after stripping The help is alright. The [^\w\.@-] should be parsed into [^\w], [^\.], >out all nonalphanumeric characters except @, - (a dash), >and . (a period)." [^@], 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. 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. > 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. 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
.empty
Rnd() vs. Long ...no joy with LSB! Best Practices Replacement code for Threading.Thread.Sleep VB2005 Control Arrays Enumerating MDIList Menu Item at Run-Time difference between cstr vs .ToString vs Ctype Visual Studio 2005 Outlook 2000 Wait while processing dialog boxes (threading?) COM usage problem? |
|||||||||||||||||||||||