Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
^%s_([0-9]+)\\.gamesave$
/
gm

Description

TILE_WIDTH = 2 # Includes space for padding and one space between tiles formatted_board = ""

for i in range(rows):
    formatted_row = ""
    for j in range(columns):
        tile = board_string[i * columns + j]
        formatted_row += f"{tile:<{TILE_WIDTH}}"  # Left-justified formatting
    formatted_board += formatted_row.rstrip() + "\n"  # Remove trailing spaces and add newline

return formatted_board
Submitted by robert paulson - 10 months ago (Last modified 6 months ago)