basic regex question

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

    basic regex question



    ....hoping someone can help someone still new to vb.net 2005 with something
    new to him.

    ....been successfully using the regular expression validators from the
    toolbox, but now I have need to do something strictly with code.

    ....need to determine if a stored string matches a stored regular expression.

    ....not sure what to search under for an example to give me a starting point.
    I can figure out the actual expression syntax and the rest if someone can
    get me started.

    e.g., something along these lines

    dim myregex as new regex
    if mystoredstring = regex then
    DoAllKindsOfStu ff()
    end if

    Thanks

    jeff


    --
    Posted via a free Usenet account from http://www.teranews.com

  • Andrew Morton

    #2
    Re: basic regex question

    Jeff wrote:
    ...hoping someone can help someone still new to vb.net 2005 with
    something new to him.
    >
    ...been successfully using the regular expression validators from the
    toolbox, but now I have need to do something strictly with code.
    >
    ...need to determine if a stored string matches a stored regular
    expression.
    I think you're looking for the RegEx.IsMatch method.

    Andrew


    Comment

    • rowe_newsgroups

      #3
      Re: basic regex question

      On May 17, 12:52 am, "Jeff" <n...@nothingX. comwrote:
      ...hoping someone can help someone still new to vb.net 2005 with something
      new to him.
      >
      ...been successfully using the regular expression validators from the
      toolbox, but now I have need to do something strictly with code.
      >
      ...need to determine if a stored string matches a stored regular expression.
      >
      ...not sure what to search under for an example to give me a starting point.
      I can figure out the actual expression syntax and the rest if someone can
      get me started.
      >
      e.g., something along these lines
      >
      dim myregex as new regex
      if mystoredstring = regex then
      DoAllKindsOfStu ff()
      end if
      >
      Thanks
      >
      jeff
      >
      --
      Posted via a free Usenet account fromhttp://www.teranews.co m
      Off the top of my head:

      Imports System.Text.Reg ularExpressions

      If Regex.IsMatch(m ystoredstring, myregexpattern) Then
      DoAllKindsOfStu ff()
      end if

      Thanks,

      Seth Rowe

      Comment

      • Jeff

        #4
        Re: basic regex question


        "Jeff" <none@nothingX. comwrote in message
        news:464bd328$0 $16300$88260bb3 @free.teranews. com...
        >

        Okay, now I'm really confused.

        I got this figured out somewhat, but either there is a major bug somewhere,
        or I don't understand something fundamental (and it is likely the latter)

        If I uses a regular expression validator from the toolbox and the expression
        [a-zA-Z1-9]* it will properly match letters and numbers.

        The exact same regular expression in the code below fails and matches
        everything. Something seems to be going on everytime that I enter a reg
        expression with a bracket - it will work with the toolbox validator, but not
        when I use all vb code.

        Can someone explain? I'm lost.

        Dim regexobj As Regex = New Regex("[a-zA-Z1-9]*")

        If RegexObj.IsMatc h(TBUser.Text) = False Then





        --
        Posted via a free Usenet account from http://www.teranews.com

        Comment

        • rowe_newsgroups

          #5
          Re: basic regex question

          On May 18, 6:33 pm, "Jeff" <no_...@george. comwrote:
          "Jeff" <n...@nothingX. comwrote in message
          >
          news:464bd328$0 $16300$88260bb3 @free.teranews. com...
          >
          >
          >
          Okay, now I'm really confused.
          >
          I got this figured out somewhat, but either there is a major bug somewhere,
          or I don't understand something fundamental (and it is likely the latter)
          >
          If I uses a regular expression validator from the toolbox and the expression
          [a-zA-Z1-9]* it will properly match letters and numbers.
          >
          The exact same regular expression in the code below fails and matches
          everything. Something seems to be going on everytime that I enter a reg
          expression with a bracket - it will work with the toolbox validator, but not
          when I use all vb code.
          >
          Can someone explain? I'm lost.
          >
          Dim regexobj As Regex = New Regex("[a-zA-Z1-9]*")
          >
          If RegexObj.IsMatc h(TBUser.Text) = False Then
          >
          --
          Posted via a free Usenet account fromhttp://www.teranews.co m
          I'm just guessing - but it may have to do with the RegexOptions you
          are using - try experimenting with them and see if it makes a
          difference.

          Also, you might want to post some sample text and the complete regex
          pattern that is causing the problem - that way I can take a better
          look at it.

          Thanks,

          Seth Rowe

          Comment

          • Jeff

            #6
            Re: basic regex question


            "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
            news:1179536949 .522879.130760@ n59g2000hsh.goo glegroups.com.. .
            I'm just guessing - but it may have to do with the RegexOptions you
            are using - try experimenting with them and see if it makes a
            difference.
            >
            Also, you might want to post some sample text and the complete regex
            pattern that is causing the problem - that way I can take a better
            look at it.
            >
            Thanks,
            >
            Seth Rowe

            Okay, I think that I have much of this figured out. The validator through
            the toolbox (is there a good way to say this?) does not evaluate empty
            textbox values regardless of the regex expression, while the hardcoded
            version works essentially like all of the instructions that I see about
            using regex. I didn't pick up on that initially, and that was causing the
            confusion.

            I think that I have it going now.

            Thanks for the help.



            --
            Posted via a free Usenet account from http://www.teranews.com

            Comment

            Working...