Results 1 to 2 of 2

Thread: Repetition

  1. #1
    Join Date
    Dec 1969

    Default Repetition

    Here is a regular expression that matches three characters:<BR><BR>/w{3}/<BR><BR>Is there a way to write this so that it will evaluate to false if it is given MORE than three characters?<BR><BR>Put another way, how does one write a RegExp to limit the number of characters provided?

  2. #2
    Join Date
    Dec 1969

    Default RE: Repetition

    You said anything greater then 3 in your question, a {3} will not allow anything greater then 3 and also nothing less then 3. If up to 3 is ok or greater then 3 then {1,3} is what you are looking for, you should match the begining and endign of the line to avoid problems. Here is a quick and dirty sample.<BR><BR>&#060;%<BR>Dim objRegExp, strTestString<BR>Set objRegExp = New Regexp<BR><BR>&#039;Uncomment Lines For Testing<BR>&#039;strTestString ="HelloThis is a long string that should fail"<BR>strTestString ="1345"<BR><BR>objRegExp.Global = True<BR>objRegExp.IgnoreCase = True<BR>&#039;objRegExp.Pattern = "^w{3}$" &#039;Will error on anytying less then or greater then 3, basically ONLY 3 will work<BR>objRegExp.Pattern = "^w{1,3}$" &#039;Will error on anything greater then 3, so 1,2 and 3 characters are valid 4+ not<BR><BR>If objRegExp.Test(strTestString) Then<BR> Response.Write "Thanks for entering the correct number of parameters"<BR>Else<BR> Response.write "Opps seems you entered to many items"<BR>End If<BR><BR>Set objRegexp = Nothing<BR>%&#062;

Posting Permissions

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