Are you a RegEx bandido?

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

    Are you a RegEx bandido?

    Its not that I hate RegEx its that I have to relearn the same stuff every
    couple of months because I forget what I last learned. Common eh? So... I'm
    working on an expression to validate a MIME Type and I have a fairly decent
    pattern set up but it needs some work...

    <%--
    MIME Type
    match: type/name
    match: type/name5
    match: type/x-name
    match: type/x-name-name
    match: type/x-name+name
    match: type/x-name_name
    match: x-type/name

    fail: type-/name
    fail: type/name-
    fail: type//name
    fail: type_type/name
    ValidationExpre ssion="^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+-?\+?\.?_?[a-zA-Z0-9]+)+$"
    --%>
    <asp:RegularExp ressionValidato r
    ID="Validator1 " runat="server"
    ControlToValida te="TextBox1"
    ErrorMessage="I nvalid MIME Type Format"
    Display="Dynami c"
    Font-Bold="true"
    SetFocusOnError ="true"
    ValidationExpre ssion="^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+-?\+?\.?_?[a-zA-Z0-9]+)+$"
    />

    That part of the string that follows the / character allows a single
    instance of one of the following characters multuple times [-?|+?|.?|_?] but
    the problem is I don't know how to prevent two such allowable characters to
    preceed or follow one another...

    // currently matched but this pattern needs to fail
    type/x-.name
    // currently matched but this pattern needs to fail
    type/x.-name

    Got any idea how to express this rule?

  • A Nonymous

    #2
    Re: Are you a RegEx bandido?

    What about:

    ^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+[-+_\.]?[a-zA-Z0-9]+)+$

    I am not familliar with the rules for mime type syntax, but this should
    return valid results for the examples you have provided.

    Comment

    • Hillbilly

      #3
      Re: Are you a RegEx bandido?

      Yup good point; add another class...
      [-\+_\.]?

      "A Nonymous" <anonymous@hotm ail.comwrote in message
      news:Xns9B39AB0 E1B707anonymous hotmailcom@207. 46.248.16...
      What about:
      >
      ^([a-z]+-?[a-z]+)/([a-zA-Z0-9]+[-+_\.]?[a-zA-Z0-9]+)+$
      >
      I am not familliar with the rules for mime type syntax, but this should
      return valid results for the examples you have provided.

      Comment

      Working...