www.webdeveloper.com
Results 1 to 3 of 3

Thread: Needs help with a regular expression

  1. #1
    Join Date
    Jan 2014
    Posts
    7

    Needs help with a regular expression

    Hi list,

    For many hours now I tried to construct a regular exprsession to verify that a string:

    Is divided in substrings of maximum 8 characters (qualifiers) separated by a dot '.'
    All first characters of a qualifier should be alphabetic the others alphanumeric
    The first qualifier can not contain '*' or '%'
    The remainig qualifiers may contain '*' and '%'

    Any help would be greatly appreciated.

    j@n

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    Code:
    /^[^\.*%]{1,8}(\.[^\.]{1,8})*$/
    (I think)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Something like this can give ideas...
    Code:
    var testString="4644jkljkj.4euu56.yuiyy45"
    var textResult=testString.replace(/[^.]+/g,function(a){
         if (8<a.length) return '\n'+a+' to long substring';
         if (!(/^[A-Za-z]/.test(a))) return '\n'+a+' incorrect first character';
         return '\n'+a' ok !';
    })
    alert(textResult)
    Of course tests can be improved. For example alphabetic characters can be defined as [^\W\d*%]+ (which is alphanumeric without * and %).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles