Help with RegExp

Results 1 to 2 of 2

Thread: Help with RegExp

  1. #1
    Join Date
    Dec 1969

    Default Help with RegExp

    I can&#039;t seem to get this to work right. I have the code below (I am using VBScript), and it seems to return a match even though I have the {3,4} portion of the patern. According to everything that I can find, that should mean that it should be at least 3 but no more then 4 digits. Right? If I put in less then 3 digits it returns false, if I put in more the 4 it still returns true. Can anyone help? Thanks. <BR><BR>objRegExp.Global = false &#039;Even if set to true it makes no difference. <BR>objRegExp.Pattern = "^d{3,4}" <BR>objRegExp.IgnoreCase = True <BR>Response.Write(objRegExp.Test("1234")) &#039;Returns true <BR>Response.Write(objRegExp.Test("12")) &#039;Returns false <BR>Response.Write(objRegExp.Test("123456789")) &#039;Returns true<BR><BR>Also what would be the pattern for something like this. At least 5 characters (a-z) or more, and no other characters (no numbers, no symbols, etc.).

  2. #2
    Join Date
    Dec 1969

    Default RE: Help with RegExp

    objRegExp.Pattern = "^d{3,4}" <BR><BR>You have to add &#039;$&#039; to the end of the pattern, which means &#039;the end of input&#039;. Otherwise, you are receiving True because it finds 3 o 4 digits, and then more digits. Your RE says "match strings beginning with 3 o 4 digits". When you add the $, your pattern becomes "^d{3,4}$", which means "match strings that consist only of 3 o 4 digits".<BR><BR>The Global property makes no difference in *your* scenario, but if set to False it tells the RegExp object to stop as soon as it finds a match. Setting it to True forces the object to find as many matches.<BR><BR>Hope it helps (I&#039;m Spanish!!) ;)<BR><BR>MOS

Posting Permissions

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