EasyRegex Logo
EasyRegex
Neu

Matching 'tic' and 'tac' with specific conditions

python

Regulärer Ausdruck

^(tac|tictac)+(tac){2,}tictac(tac|tac|^)
Kopieren
Haben Sie Feedback?

Erklärung

This regex pattern matches strings that consist of 'tic' or 'tac' with the following conditions: 1. 'tic' should not be the immediate neighbor of itself, 2. The first occurrence of 'tic' must only happen after 'tac' has appeared at least twice before.

python

Beispielverwendung

import re

test_string = 'tactactictactac'
regex_pattern = r'^(tac|tictac)+(tac){2,}tictac(tac|tac|^)'
matches = re.fullmatch(regex_pattern, test_string)
if matches:
    print('String matches the pattern')
Kopieren
Testen Sie den Ausdruck

Ähnliche Reguläre Ausdrücke