Regular Expressions 101

Community Library

Community Library Entry

1

Regular ExpressionOpen Workspace

r"
^(?:(?:(?P<piece>[prnbkq])?\s*(?P<from_col>[a-h])?(?P<from_row>[1-8])?\s*(?P<capture>x)?\s*(?P<to>[a-h][1-8]))|(?P<k_castling>(?P<char>[0O])\s*-\s*(?P=char))|(?P<q_castling>(?P<char2>[0O])\s*-\s*(?P=char2)\s*-\s*(?P=char2)))$
"
igm

Description
Created·2025-07-07 19:15
Type·Match
Flavor·Python

Detects chess Algebraic notation. See: https://en.wikipedia.org/wiki/Algebraic_notation_(chess)

Using Regexp groups to know what information is present on the notation (pieces or move disambiguation).

Only supported by Flavor that has named group verification.

Submitted by Johan JANIN
Open Workspace