Last active
February 3, 2025 16:40
-
-
Save mlforcada/8fdc31ec7f0fe51add98d831bef63121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Generate a regular expression for amateur radio call signs | |
| # Mikel L. Forcada 2025 | |
| # Public domain software | |
| # strict or lax matching | |
| strict="yes" | |
| # strict = ITU https://www.itu.int/pub/R-REG-RR-2024, section III, article 19 | |
| # change to "no" or anything else if you want to match callsigns such as E7W, D4A or very long call signs | |
| # build prefix | |
| if [[ "$strict" == "yes" ]]; then | |
| prefix="([BFGKIMNRW]|[0-9Ø][A-Z]|[A-Z][0-9Ø]|[A-Z][A-Z])" | |
| else | |
| # for the time being, allow any single letter | |
| prefix="([A-Z]|[0-9Ø][A-Z]|[A-Z][0-9Ø]|[A-Z][A-Z])" | |
| fi | |
| digit="[0-9Ø]" | |
| # build premodifier | |
| # TR 61-01 premodifiers are prefixes, optionally followed by a digit, followed by a slash | |
| premodifier="$prefix($digit)?[/]" | |
| # build suffix | |
| if [[ "$strict" == "yes" ]]; then | |
| suffix="[A-Z0-9Ø]{0,3}[A-Z]" | |
| else | |
| # allow for longer suffixes | |
| # this still does not accept observed call signs such as 7Q1 | |
| suffix="[A-Z0-9Ø]*[A-Z]" | |
| fi | |
| # build postmodifier | |
| # postmodifiers taken from DARC's "Countries with CEPT Licence" | |
| postmodifier="[/]($prefix($digit)?|(M|P|B|MM|AM|A|MA|[0-9]))" | |
| # build regular expression | |
| callsign="($premodifier)?$prefix$digit$suffix($postmodifier)?" | |
| echo $callsign | |
| # test input | |
| egrep "^$callsign$" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment