0

I have the following regex expression:

(?<=[^:]:)?([a-zA-Z]{6}\w[a-zA-Z]{4})

Which is looking for every instance of SWIFT BIC code.

The SWIFT code consists of 8 or 11 characters. When 8-digits code is given, it refers to the primary office.

  1. First 4 characters - bank code (only letters)
  2. Next 2 characters - ISO 3166-1 alpha-2 country code (only letters)
  3. Next 2 characters - location code (letters and digits) (passive participant will have "1" in the second character)
  4. Last 3 characters - branch code, optional ('XXX' for primary office) (letters and digits)

So given the list items above and my regex expression, i'm trying to lift out of this exmaple string all the BICS. The screen shot shows, what i'm watching, correctly and wrongly.

enter image description here

You can see at the top, that i'm not there. I need to only pull back these:

  • BARCGB2LXXX
  • BARCGB2LXXX
  • HSBCGB2LXXX
  • HSBCGB2LXXX
  • RBOSGB2RTCM
  • SABCIR2HXXX

EDIT

Perhaps may be best to quantify that this regex is intended to be used within .NET application

aff
  • 162
  • 2
  • 6
  • 17
CSharpNewBee
  • 1,951
  • 6
  • 28
  • 64

1 Answers1

2

assuming the code to be at the end of every string, this will work:

[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$

demo here

aelor
  • 10,892
  • 3
  • 32
  • 48