Skip to content

Instantly share code, notes, and snippets.

@JoshuaCarroll
Last active November 6, 2023 22:25
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JoshuaCarroll/f6b2c64992dfe23feed49a117f5d1a43 to your computer and use it in GitHub Desktop.
Save JoshuaCarroll/f6b2c64992dfe23feed49a117f5d1a43 to your computer and use it in GitHub Desktop.
Regular expression (regex) for non-US amateur radio call signs
All amateur radio call signs:
[a-zA-Z0-9]{1,3}[0-9][a-zA-Z0-9]{0,3}[a-zA-Z]
Non-US call signs:
\b(?!K)(?!k)(?!N)(?!n)(?!W)(?!w)(?!A[A-L])(?!a[a-l])[a-zA-Z0-9][a-zA-Z0-9]?[a-zA-Z0-9]?[0-9][a-zA-Z0-9][a-zA-Z0-9]?[a-zA-Z0-9]?[a-zA-Z0-9]?\b
US call signs:
[AKNWaknw][a-zA-Z]{0,2}[0-9][a-zA-Z]{1,3}
@shrop
Copy link

shrop commented Apr 22, 2021

Thank you for sharing these! 73, KF4ZZF

@JoshuaCarroll
Copy link
Author

Thank you for sharing these! 73, KF4ZZF

You're very welcome! What are you making? (Just curious.) de AA5JC

@PopeFelix
Copy link

I'm using these for a Python script to print out address labels for QSL cards from an ADI file. Trying to handle "slashy" call signs (e.g. POTA/W1ABC or K0XYZ/2) and parse out the call sign

73 de W0KEH

@JoshuaCarroll
Copy link
Author

I'm using these for a Python script to print out address labels for QSL cards from an ADI file. Trying to handle "slashy" call signs (e.g. POTA/W1ABC or K0XYZ/2) and parse out the call sign

73 de W0KEH

Without seeing your sample set it's hard to write, but I took a stab at it anyway..

RegExpr.com - Good visual of the regex
regex101 - Great for testing regex against sample data

@Goorzhel
Copy link

Silly question, but why [0123456789] instead of [0-9]?

@JoshuaCarroll
Copy link
Author

Silly question, but why [0123456789] instead of [0-9]?

Probably because I didn't know regex that well back when I wrote this.
¯_(ツ)_/¯

@kj7rrv
Copy link

kj7rrv commented Aug 9, 2022

Thank you! I'm using this to validate call signs in a program to create accounts on a ham radio club station computer.

@tonyg57
Copy link

tonyg57 commented Dec 11, 2022

Thanks for providing this! I modified the expression to not match calls like: A6AA, A6AAA, AAA6A since these don't follow the U.S. rules. Also calls in the range AM* to AZ* don't get matched either.

Modified RegEx: ^[KNWknw][a-zA-Z]{0,2}[0-9][a-zA-Z]{1,3}$|^[Aa][a-lA-L]{1}[0-9][a-zA-Z]{1,2}$

This matches the whole string too. Been using this to validate U.S. callsigns in the DMR database as well as finding several malformed U.S. calls.

@shrop
Copy link

shrop commented Dec 11, 2022

@JoshuaCarroll Just saw your comment. Learning Flutter and making a simple call sign lookup iOS and Android app.

@JoshuaCarroll
Copy link
Author

Very cool! Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment