I’m using GSKinner’s Reg Exr tool to help come up with a pattern that can locate authorization numbers in a field that contains a whole lot of other garbage. The authorization number is a string that contains letters (sometimes), numbers (always), and hyphens (sometimes) (i.e. the authorization always contains a number somewhere, but doesn’t always contains hyphens and letters). Additionally, the authorization number can be located anywhere in the field I am searching.
Examples of proper 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’s some sample data with the additional garbage, which is sometimes appended to the real authorization number with a hyphen or no space, making it look like part of the number. The garbage comes though in predictable forms/words: REF, CHEST, IP, AMB, OBV, and HOLD that are not part of 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’s the pattern I’m using:
"\b[a-zA-Z]*[\d]+[-]*[\d]*[A-Za-z0-9]*[\b]*"
I’m learning RegExp so it no doubt can be improved, but it works for the above, just not for the below 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 someone help?
For testing purposes, here’s Sub that creates a table with sample input data:
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
Your sample inputfile (path to this file s/b given to
function<GetMatches>asinputFilePath):here’s the junks saved in file(path to this file s/b given to
function<GetMatches>asreplaceDBPath):And here goes the
bas:And a sample tester
may be called from
immediate window:Hope this helps.