Last active
March 26, 2023 00:47
-
-
Save kionay/2521a2ac744104266ef72cbf1fd4fb95 to your computer and use it in GitHub Desktop.
Regular Expression for matching spreadsheet cells with A1 notation
This file contains 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
^(?:(?'startcolumn'[A-Za-z]{1,3})(?'startrow'\d{1,7}):(?'endcolumn'[A-Za-z]{1,3})(?'endrow'\d{1,7}))$|^(?:(?'startcolumn'[A-Za-z]{1,3}):(?'endcolumn'[A-Za-z]{1,3}))$|^(?:(?'startcolumn'[A-Za-z]{1,3})(?'startrow'\d{1,7}))$|^(?:(?'startcolumn'[A-Za-z]{1,3})(?'startrow'\d{1,7}):(?'endcolumn'[A-Za-z]{1,3}))$|^(?:(?'startcolumn'[A-Za-z]{1,3})(?'startrow'\d{1,7}):(?'endrow'\d{1,7}))$|^(?:(?'startcolumn'[A-Za-z]{1,3}):(?'endcolumn'[A-Za-z]{1,3})(?'endrow'\d{1,7}))$|^(?:(?'startrow'\d{1,7}):(?'endrow'\d{1,7}))$|^(?:(?'startrow'\d{1,7}):(?'endcolumn'[A-Za-z]{1,3})(?'endrow'\d{1,7}))$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses overlapping named capture groups so it only works with in C# with .NET's regex engine.
This is actually 8 regular expressions OR'd together, each one identifying a different format.
A1:B2
A:B
A1
A1:B
A1:2
A:B2
1:2
1:B2