Regular Expressions 101

Community Patterns

PTN Ply Matching

1

Regular Expression
PCRE (PHP <7.3)

/
(?<=^|\n)(?P<spacer>[[:blank:]]*(?:\{[^{]*(?&spacer)[^}]*\}[[:blank:]]*)[[:blank:]]*|[[:blank:]]+)(\d+)\.(?&spacer)(?:([1-8])?([a-h])([1-8])([+-<>])([1-8]*)|([FSC])?([a-h])([1-8]))(?:(?&spacer)(?:([1-8])?([a-h])([1-8])([+-<>])([1-8]*)|([FSC])?([a-h])([1-8])))?(?&spacer)?(?=$|\n)
/
g

Description

PTN (Portable Tak Notation) is a format to transport the history of a played game of Tak. The body of PTN files consists of ordered lines of moves, each consisting of one or two plies. This pattern parses PTN move lines and groups interesting information in useful groups.

Submitted by TreffnonX (Janis Schöck) - 8 years ago