Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegEx for ISIN with at least 1 number

Tags:

regex

I have the following RegEx to parse ISIN of bonds, assets, etc.. (2 characters followed by 10 digits and characters)

([A-Z]{2})([A-Z0-9]{10})

But this also marks for example a word like this ABCDEFGHIJKL, but this is no real ISIN. A definition of ISINs is here: WIKI

So some examples are US45256BAD38, US64118Q1076, XS0884410019. What would be the correct RegEx to search for them, without matches like ABCDEFGHIJKL?

Maybe with a RegEx to have at least one number?

like image 719
ZerOne Avatar asked Oct 16 '15 07:10

ZerOne


1 Answers

If you can not use lookahead according to the Wikipedia defintion you can also just check if the last character is a number as it should be the check digit.

ISINs consist of two alphabetic characters, which are the ISO 3166-1 alpha-2 code for the issuing country, nine alpha-numeric characters (the National Securities Identifying Number, or NSIN, which identifies the security, padded as necessary with leading zeros), and one numerical check digit.

Source: https://en.wikipedia.org/wiki/International_Securities_Identification_Number#Description

Meaning this also could work:

([A-Z]{2})([A-Z0-9]{9})([0-9]{1})
like image 160
sipho102 Avatar answered Dec 06 '22 16:12

sipho102