Regex.Replace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cj

    #1

    Regex.Replace

    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(ByVa l strIn As String) As String
    ' Replace invalid characters with empty strings.
    Return Regex.Replace(s trIn, "[^\w\.@-]", "")
    End Function
  • cj

    #2
    Re: Regex.Replace

    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:[color=blue]
    > 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(ByVa l strIn As String) As String
    > ' Replace invalid characters with empty strings.
    > Return Regex.Replace(s trIn, "[^\w\.@-]", "")
    > End Function[/color]

    Comment

    • cj

      #3
      Re: Regex.Replace

      system.Text.Reg ularExpressions .Regex.Replace

      cj wrote:[color=blue]
      > 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(ByVa l strIn As String) As String
      > ' Replace invalid characters with empty strings.
      > Return Regex.Replace(s trIn, "[^\w\.@-]", "")
      > End Function[/color]

      Comment

      • Gary Chang[MSFT]

        #4
        Re: Regex.Replace

        Hi,
        [color=blue]
        >The help says, "CleanInput returns a string after stripping
        >out all nonalphanumeric characters except @, - (a dash),
        >and . (a period)."[/color]

        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.

        Comment

        • cj

          #5
          Re: Regex.Replace

          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:[color=blue]
          > Hi,
          >[color=green]
          >> The help says, "CleanInput returns a string after stripping
          >> out all nonalphanumeric characters except @, - (a dash),
          >> and . (a period)."[/color]
          >
          > 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.
          >[/color]

          Comment

          • Gary Chang[MSFT]

            #6
            Re: Regex.Replace

            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.

            Comment

            Working...