简体   繁体   中英

Java Regex to match for Letter in last 3 characters of 11 character long swift code

Working with worldwide Swift Codes.

The swift code's I'm looking to match are of the 11 character variety where the last 3 digits are alphanumeric (A-Z0-9).

The match should occur whenever a letter or letters are in the last 3 digits, in any location.

I have another regular expression that matches on Swift Codes where the last 3 digits are simply numbers only. Looks like this below.

The relevant portion would be the [0-9]{3} portion at the end, which currently hits only on numbers.

[A-Z0-9]{3} will not work correctly as it will falsely match on 3 numbers.

How would the regex be updated to match for a swift code where a letter or letters are present in the last 3 characters of an 11 character code?

(?:\s|\u00A0|^)((?:[A-Z]{4}[AD|AE|AF|Ag|AI|AL|AM|AO|AQ|AR|AS|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BL|BM|BN|BO|BQ|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CU|CV|CW|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MCMD|ME|MF|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|SS|ST|SV|SX|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TR|TT|TV|TW|TZ|UA|UG|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|ZA|ZM|ZW]{2}[A-Z0-9]{2}[0-9]{3}))(?:\s|\u00A0|$)

There may be a more concise way, but this should do the trick for matching the 3 alphanumeric characters at the end that contain at least 1 letter.

[A-Z][A-Z0-9]{2}|[A-Z0-9][A-Z][A-Z0-9]|[A-Z0-9]{2}[A-Z]

You can test it here . See the unit tests tab on the left.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM