Micro Focus QTP (UFT) Forums
Find pattern for series from 1287 to 9834 - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Regular Expressions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Regular-Expressions)
+--- Thread: Find pattern for series from 1287 to 9834 (/Thread-Find-pattern-for-series-from-1287-to-9834)



Find pattern for series from 1287 to 9834 - abhideshpande001 - 07-28-2015

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


RE: Find pattern for series from 1287 to 9834 - abhideshpande001 - 07-29-2015

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])"



RE: Find pattern for series from 1287 to 9834 - akhi_s27 - 07-29-2015

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})
      )
     )
    )
   )
  )
)
)



RE: Find pattern for series from 1287 to 9834 - abhideshpande001 - 08-05-2015

Thanks Mate. Smile