Jump to the post that solved this thread.
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find pattern for series from 1287 to 9834
#1
Solved: 9 Years, 3 Months, 3 Weeks ago
I have created pattern like this. but it is giving me incorrect result. Please help me with this.

Code:
patrn="([1][2-9][0-9][0-9]|[9][8-9][0-3][0-3]|9834)"
strng1=1286
Dim regEx, retvalb4                    ' Create variable.
Set regEx = New RegExp             ' Create regular expression.
regEx.Pattern = patrn                  ' Set pattern.
regEx.IgnoreCase = False             ' Set case sensitivity.
regEx.global=true
retvalb4 = regEx.Test(strng1)      ' Execute the search test.
msgbox retvalb4


Smile
Reply
#2
Solved: 9 Years, 3 Months, 3 Weeks ago
This pattern would work.

Code:
patrn="([1-8][2-8][8-9][7-9]|[2-8][0-9][0-9][0-9]|[9][0-8][0-3][0-4])"
Reply
#3
Solved: 9 Years, 3 Months, 3 Weeks ago
This regex has many flaws.
for eg: 1900 is not getting matched which is withing the range.

these types of conditions are best if handled in code than by regex.
Anyways...the regex for this specific condition is as below:

Code:
(?(^128[7-9]{1}$)(128[7-9])
|(?(^12[8-9]\d$)(12[8-9]\d)
|(?(^1[2-9]\d{2}$)(1[2-9]\d{2})
  |(?(^[2-8]\d{3}$)([2-9]\d{3})
   |(?(^983[0-4]$)(983[0-4])
    |(?(^98[0-3]\d$)(98[0-3]\d)
     |(?(^9[0-8]\d{2}$)(9[0-8]\d{2})
      )
     )
    )
   )
  )
)
)
Reply
#4
Solved: 9 Years, 3 Months, 3 Weeks ago
Thanks Mate. Smile
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 2 Guest(s)