I use the GSKinner Reg Exr tool to help create a template that can find authorization numbers in a field that contains a lot of other garbage. An authorization number is a string containing letters (sometimes), numbers (always) and hyphens (sometimes) (that is, authorization always contains a number somewhere, but does not always contain hyphens and letters). In addition, the authorization number can be located anywhere in the field I'm looking for.
Examples of valid authorization numbers include:
5555834384734 ' All digits 12110-AANM ' Alpha plus digits, plus hyphens R-455545-AB-9 ' Alpha plus digits, plus multiple hyphens R-45-54A-AB-9 ' Alpha plus digits, plus multiple hyphens W892160 ' Alpha plus digits without hypens
Here are some examples of data with extra garbage that is sometimes added to a real authorization number with a hyphen or missing space, which makes it look like part of a number. Garbage comes, although in predictable forms / words: REF, CHEST, IP, AMB, OBV and HOLD, which are not included in the authorization number.
5557653700 IP R025257413-001 REF 120407175 SNK601M71016 U0504124 AMB W892160 019870270000000 00Q926K2 A025229563 01615217 AMB 12042-0148 SNK601M71016 12096NHP174 12100-ACDE 12110-AANM 12114AD5QIP REF-34555 3681869/OBV ONL
Here is the template I am using:
"\b[a-zA-Z]*[\d]+[-]*[\d]*[A-Za-z0-9]*[\b]*"
I am studying RegExp, so it can no doubt be improved, but it works for the above, and not for the following situations:
REFA5-208-4990IP 'Extract the string 'A5-208-4990'without REF or IP OBV1213110379 'Extract the string '1213110379' without the OBV 5520849900AMB 'Extract the string '5520849900' without AMB 5520849900CHEST 'Extract the string '5520849900' without CHEST 5520849900-IP 'Extract the string '5520849900' without -IP 1205310691-OBV 'Extract the string without the -OBV R-025257413-001 'Numbers of this form should also be allowed. NO PCT 93660 'If string contains the word NO anywhere, it is not a match HOLDA5-208-4990 'If string contains the word HOLD anywhere, it is not a match
Can anyone help?
For testing purposes, here is Sub, which creates a table with sample input:
Sub CreateTestAuth() Dim dbs As Database Set dbs = CurrentDb With dbs .Execute "CREATE TABLE tbl_test_auth " _ & "(AUTHSTR CHAR);" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('5557653700 IP');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "(' R025257413-001');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('REF 120407175');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('SNK601M71016');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('U0504124 AMB');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('3681869/OBV ONL');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('REFA5-208-4990IP');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('5520849900AMB');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('5520849900CHEST');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('5520849900-IP');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('1205310691-OBV');" .Execute " INSERT INTO tbl_test_auth " _ & "(AUTHSTR) VALUES " _ & "('HOLDA5-208-4990');" .Close End With End Sub