Examples


In the discussion so far you have seen the ScannerVision metadata functions used in fairly trivial expressions. In this section we present several more complex examples of how you can use these functions.

Throughout the examples we’ll use the fictitious BC tag which holds our sample data. If you want to try out these examples for yourself, copy and paste the expression into the ScannerVision Expression Editor. The first time you do this, the Expected Output window will show the un-parsed expression and you will see the “BC” tags appear in the Used Tags grid. Once you have entered some sample data into the grid the expression will parse as usual. Alternatively, you can put the sample data in double quotes in the place of the BC tag e.g.

["2013/05/25" (split "/")(join "-")]

We present the sample data in the examples in double quotes so that you can see if there are leading or trailing non-printable characters included in the data. When you copy the sample data, make sure to copy everything BETWEEN the quotes and not to include the quotes themselves - unless of course you use the shorthand shown above in which case you must include the quotes as well.

Reformat Date and Time
Requirement Replace "/" with "-" in date.
Sample data "2013/05/25"
Expression [BC (replace "/" "-")]
Result 2013-05-25
Requirement Convert date and time to UTC format.
Sample data "05/25/2013 23:07:48"
Expression [BC (split "/| ")(take 3, 1, 2)(join "-")]T[BC (split " ")(take 2)]Z
Result 2013-05-25T23:07:48Z
Requirement Ensure that month and day have a leading zero and replace "/" with "-".
Sample data "2013/3/4"
Expression [DATETIME (split "/")(lpad '0', 2)(join "-")]
Result 2013-03-04


Character case
Requirement Ensure that the name of day start with a capital letter and the remaining letters are lowercase.
Sample data "monday", "MONDAY", "moNDaY"
Expression [BC (ucase)(take 1)][BC (lcase)(take 2-)]
Result Monday


Email address
Requirement Create a string of semi-colon delimited email addresses given the TO field from an email message header.
Sample data ""Some User1", <someuser1@domain.com>, "Some User2", <someuser2@domain.com>"
Expression [BC (match "[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})")(join "; ")]
Result someuser1@domain.com; someuser2@domain.com


Note

To create a Regex that will match every possible form of email address is no trivial task. The one presented here will match most common forms but you will have to adapt it for specific situations if this one is not sufficient.

Matching
Requirement Extract all 2 digit numbers from a string.
Sample Data "ab12cd34ef56qw1we3"
Expression [BC (match "\d\d")]
Result 123456


Find nth last instance
Requirement Find last subfolder name in a folder path with an unknown number of subfolders
Sample Data "C:\Users\Public\Documents\microsoft\"
Expression (split "\\")(remove)(reverse)(take 1)
Result microsoft


Note

Since the split function takes a regular expression the backslash needs to be escaped.

Since the sample data contains a trailing backslash the split function will split on the last backslash which results in an empty last element in the string array. The remove function without a parameter removes all empty elements in the string array. If you omitted the remove function you would have needed to use “take 2” instead.

This technique above can be used to get any last nth element in the array by just specifying the relevant instance in the take function call.

Extract directory
Requirement Find the directory only of a fully qualified path.
Sample Data "C:\Users\Public\Documents\microsoft\filename.tiff"
Expression (match "(.+\\)*")
Result C:\Users\Public\Documents\microsoft\


Note

Since the match function takes a regular expression the backslash needs to be escaped.

For this expression to work reliably the path:

· Has to contain a file name

OR

· Has to end with a trailing backslash

Otherwise the last sub directory will be stripped off e.g. “C:\Users\Public\Documents\microsoft” will end up as “C:\Users\Public\Documents"