Reputation: 9
I'm trying to match passport numbers in emails I receive in Outlook. Basically, the marker can be any of the following formats:
Pass 1234567
Pass, 11223344
Pass: 1234567
Passport # is HA12345678.
Passport #: G7654321
Passport: 1234567 (Nepal)
Passport No 123456789
Passport No.: 123456789
Passport No: TG1234567
Passport Number 1234567
Passport Number - 5432198765
passport number, AH123456789
Passport Number: AB123456
Passport/Travel Document Number: AZ0912345
I'm only interested in capturing the bold number part but it must be in close proximity to the Pass* label because there are other numbers in the email that could be misinterpreted as passport numbers.
I'm using VBScript Regular Expressions 5.5 under VBA (Word & Outlook) Office 2010 under Windows 7. I believe this flavor of regex is most closely related to that used in JavaScript?
Upvotes: 0
Views: 1772
Reputation: 7
^(?:[A-Z 0-9]{2})[0-9]{5,10}$
where:
^
represents the starting of the string.(
represents the starting of the group.
?
represents the 0 or 1 time.[A-Z 0-9]{2}
represents the next two alphabets/digits should be any between A-Z/0-9.)
represents the ending of the group.[0-9]{5,10}
represents the next digits should be any between 0-9 and min 5 and max 10$
represents the ending of the string.Upvotes: 0
Reputation: 15000
This regex will match strings which start with 2 alphanumeric characters and continue with between 5 and 10 more alpha numeric characters. I'm allowing so many characters because the sample text had a range of desired string sizes.
\b[a-zA-Z0-9]{2}[0-9]{5,10}\b
your 14 lines of input sample text
Pass 1234567
Pass, 11223344
Pass: 1234567
Passport # is HA12345678.
Passport #: G7654321
Passport: 1234567 (Nepal)
Passport No 123456789
Passport No.: 123456789
Passport No: TG1234567
Passport Number 1234567
Passport Number - 5432198765
passport number, AH123456789
Passport Number: AB123456
Passport/Travel Document Number: AZ0912345
[0] => 1234567
[1] => 11223344
[2] => 1234567
[3] => HA12345678
[4] => G7654321
[5] => 1234567
[6] => 123456789
[7] => 123456789
[8] => TG1234567
[9] => 1234567
[10] => 5432198765
[11] => AH123456789
[12] => AB123456
[13] => AZ0912345
Upvotes: 1