Select to view content in your preferred language

How To Use RegEx to Decode VIN

4793
5
01-27-2017 03:21 PM
Christopher_L_Rogers
Regular Contributor

I'm looking to see if there's any information about using a Regular Expression in Survey123 to decode a Vehicle Identification Number (17 Character String) to extract Year, Make, and Model from the VIN String into other fields name as such.

I'm fairly certain it can be done but with regards to using Functions within Survey123 the data is fairly vague and not specific enough to know if a RegEx can be used to parse a string as well as force input formatting.

Here's a string that is supposed to decode/parse a VIN but I can't seem to find the proper place to use it in Survey123 to even try it out... suspecting that it would have to be placed in the Calculations area but not sure.

/^(?:([A-HJ-NPR-Z]){3}|\d{3})(?1){2}\d{2}(?:(?1)|\d)(?:\d|X)(?:(?1)+\d+|\d+(?1)+)\d{6}$/i

Tags (1)
0 Kudos
5 Replies
JamesTedrick
Esri Esteemed Contributor

Regex functions don't decode text; they verify that a given input matches the pattern specified; as an example, the e-mail regex, /^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/ , checks that the text starts with some combination of letters & numbers ( ^([a-zA-Z0-9_\-\.]+) ), has an @ symbol, has more text/numbers ( ([a-zA-Z0-9_\-\.]+)\ ), a period, and then between 2-5 letters at the end ( ([a-zA-Z]{2,5})$ ).

What you would want is to use the substr() function to extract individual characters, and then most likely use them with either select_one choice values or a pulldata() function to look up the values in a set of external CSV.  To do this, you need to have a VIN database already- it looks like NHTSA might have the information at Vehicle API 

Christopher_L_Rogers
Regular Contributor

Actually James you can use RegEx to decode or parse strings in certain IDE/Languages such as in .NET using "Regex.Split Method (String, String)" which splits an input string into an array of substrings at the positions defined by a regular expression pattern.

While this may not be a capability within Survey123 it would be nice to add it to the Wish List so that you don't have to rely on characters counts as you do with SubStr() so that you can call the RegEx.split() function and use patterns to define what parts of the String you want to use to define something else such as in my case the two digits which represent Vehicle Year, Make, or Model, etc...

If the Survey123 SubStr() Function would allow you to define how you want to parse a string start char, stop char, number of chars it might be easier to do it that way but the Survey123 implementation of SubStr() seems a bit limited but that just may be my limited understanding of how the function is implemented. I can't seem to find a Functions list for what functions are available for use in Survey123 and how they are implemented versus how other languages implement them so I am sometimes at a bit of a loss without some laborious experimentation.

Long story short I'd really LOVE to have a document on the Functions available within Survey123.

Thanks for your assistance!

Regards,
Chris

0 Kudos
Christopher_L_Rogers
Regular Contributor

Almost forgot here's the Microsoft link to RegEx.Split() function... https://msdn.microsoft.com/en-us/library/8yttk7sy(v=vs.110).aspx

0 Kudos
JamesTedrick
Esri Esteemed Contributor

The full list of functions is listed in the Quick Reference section of the documentation.  Survey123 uses the XLSForm specification definition of what the regex function does (and other functions do)- those functions are subsequently interpreted and then run in application code (what you type in the XLS file is not directly executed; this is a safety measure).  In regex's case, the function is the equivelant of a regular expression test function - return true if the pattern is matched.

Christopher_L_Rogers
Regular Contributor

Ah that makes sense then that it will only allow for Pattern Matching.

Thanks for the updated link this will be a major help - http://doc.arcgis.com/en/survey123/desktop/create-surveys/quickreferencecreatesurveys.htm

The one I had and had been using didn't have the other function and references - https://doc.arcgis.com/en/survey123/desktop/get-answers/quickreferencegetanswers.htm

The "Quick reference" under the Get Answers tab in the Survvey123 website is different than the one under the Create Surveys tab and since they're both labeled "Quick reference" it was a bit misleading/confusing...

Thanks again for the link...!!!

0 Kudos