none
VB Script Help with returned string length !! RRS feed

  • Question

  • Hi

    I have used a similar script as the one posted below but I have a new question.

    my script looks for a set of numbers beginning 04 then outputs the rest of the numbers that follows it but I am finding that if the text on a page has another set of numbers containing 04 it obviously reads this also.

    so...if possible, as the required numbers are always 6 digits long, can I edit the script to only output the digits that begin with 04 and are 6 digits long. eg 045678 will output but 0456789 will be ignored.

    thanks for any help !!

    ocrText = Metadata.Values("OCR_ZONE01")

    'Variables contain the regular expressions that will be use to look for the required information, will need to be modified when more combinations may occur
    Dim Target, Target2
    Target = ".*(04)([A-z]*[0-9]+)"
    Target2 = ""

    Dim arrLines
    arrLines = Split(ocrText, "\r\n")

    call Metadata.SetValues("MY_TEXT", "## NOT FOUND ##")
    'call Metadata.SetValues("MY_SUPPLIER", "## NOT FOUND ##")

    Dim matchedValue

    'Then you can iterate it like this 
    For Each strline in arrLines 
     match = GetFirstMatch(target, strline)
     If match <> "" Then
      call Metadata.SetValues("MY_TEXT", match)
     End If
     'match = GetFirstMatch(target2, strline)
     'If match <> "" Then
     ' call Metadata.SetValues("MY_SUPPLIER", match)
     'End If
    Next


    ' Get the first objRE  submatch from the string
    ' Returns empty string if not found, otherwise returns the matched string
    Function GetFirstMatch(PatternToMatch, StringToSearch)
     Dim objRE , CurrentMatch, objMatch

     Set objRE  = New RegExp
     objRE.Pattern = PatternToMatch
     objRE.IgnoreCase = True
     objRE.Global = False

     Set objMatch = objRE.Execute(StringToSearch)
     
     GetFirstMatch = ""
     ' We should get only 1 match since the Global property is FALSE
     If objMatch.Count = 1 Then
      ' Item(0) is the (first and only) matching target parts,
      ' Submatches(1) is the substring between the second set of
      ' parentheses (all indexes are zero based)
      GetFirstMatch = objMatch.Item(0).Submatches(0) + objMatch.Item(0).Submatches(1)
     End If
      
     Set objRE  = Nothing
    End Function

    • Moved by Bill_Stewart Friday, July 7, 2017 6:06 PM This is not support forum for third party software
    Monday, May 8, 2017 10:14 AM

All replies

  • Only 6 digit numbers beginning with 04:

    "04\d{4,4}\b}"


    \_(ツ)_/


    • Edited by jrv Monday, May 8, 2017 11:31 AM
    Monday, May 8, 2017 11:31 AM
  • Thanks for the reply. could you look at the below script. I have edited as I believe right but I get a ##NOT FOUND## error. Thanks for your help.

    ocrText = Metadata.Values("OCR_ZONE01")
    'Variables contain the regular expressions that will be use to look for the required information, will need to be modified when more combinations may occur
    Dim Target, Target2
    Target = "(04\d{4,4}\b}([A-z]*[0-9]+))"
    Target2 = ""
    Dim arrLines
    arrLines = Split(ocrText, "\r\n")
    call Metadata.SetValues("MY_TEXT", "## NOT FOUND ##")
    'call Metadata.SetValues("MY_SUPPLIER", "## NOT FOUND ##")
    Dim matchedValue
    'Then you can iterate it like this
    For Each strline in arrLines
     match = GetFirstMatch(target, strline)
     If match <> "" Then
      call Metadata.SetValues("MY_TEXT", match)
     End If
     'match = GetFirstMatch(target2, strline)
     'If match <> "" Then
     ' call Metadata.SetValues("MY_SUPPLIER", match)
     'End If
    Next

    ' Get the first objRE  submatch from the string
    ' Returns empty string if not found, otherwise returns the matched string
    Function GetFirstMatch(PatternToMatch, StringToSearch)
     Dim objRE , CurrentMatch, objMatch
     Set objRE  = New RegExp
     objRE.Pattern = PatternToMatch
     objRE.IgnoreCase = True
     objRE.Global = False
     Set objMatch = objRE.Execute(StringToSearch)
     
     GetFirstMatch = ""
     ' We should get only 1 match since the Global property is FALSE
     If objMatch.Count = 1 Then
      ' Item(0) is the (first and only) matching target parts,
      ' Submatches(1) is the substring between the second set of
      ' parentheses (all indexes are zero based)
      GetFirstMatch = objMatch.Item(0).Submatches(0) + objMatch.Item(0).Submatches(1)
     End If
      
     Set objRE  = Nothing
    End Function

    Tuesday, May 9, 2017 1:43 PM
  • Sorry but we do not fix arbitrary scripts that use third party tools.  YOU will have to post with your OCR provider for assistance.


    \_(ツ)_/

    Tuesday, May 9, 2017 4:53 PM