私はGSKinnerのRegExrツールを使用して、他の多くのゴミを含むフィールドで認証番号を見つけることができるパターンを考え出すのに役立てています。認証番号は、文字(場合によっては)、数字(常に)、およびハイフン(場合によっては)を含む文字列です(つまり、認証には常にどこかに数字が含まれますが、ハイフンと文字が含まれるとは限りません)。さらに、認証番号は、検索しているフィールドのどこにでも配置できます。
適切な認証番号の例は次のとおりです。
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
これは、追加のガベージを含むサンプルデータです。これは、実際の認証番号にハイフンまたはスペースなしで追加され、番号の一部のように見える場合があります。ただし、ガベージは予測可能な形式/単語(REF、CHEST、IP、AMB、OBV、およびHOLD)で発生しますが、これらは認証番号の一部ではありません。
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
これが私が使用しているパターンです:
"\b[a-zA-Z]*[\d]+[-]*[\d]*[A-Za-z0-9]*[\b]*"
私はRegExpを学習しているので、間違いなく改善できますが、以下の状況ではなく、上記の場合に機能します。
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
誰かが助けることができますか?
テストの目的で、サンプル入力データを含むテーブルを作成するSubを次に示します。
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