RegEx Lookahead/Lookbehind Examples

Here we will give a more detailed overview of what the functions should return.

Task 1 Examples

count_n_repetitions counts how often characters are repeated for n times:

text = "333"
res = count_n_repetitions(text, n=1)
# res == 2 because of the following matches
# 333
# ^^
text = "333"
res = count_n_repetitions(text1, n=2)
# res == 1 because of the following match
# 333
# ^
text = "3444553333"
res = count_n_repetitions(text, n=2)
# res == 3 because of the following matches
# 3444553333
#  ^    ^^

Task 2 Examples

count_n_reps_or_n_chars_following counts how many characters are followed by themselves for n times or by the given character. It does not count when the characters are mixed!

text = "3335567"
res = count_n_reps_or_n_chars_following(text, n=2, char="5")
# res == 2 because of the following matches
# 3335567
# ^ ^

If a character is repeated n times and defined as char it only counts once.

text = "aa"
res = count_n_reps_or_n_chars_following(text, n=1, char="a")
# res == 1 because of the following matches
# aa
# ^
text = "4455???"
res = count_n_reps_or_n_chars_following(text, n=2, char="?")
# res == 2 because of the following matches
# 4455???
#    ^^

Task 3 Examples

check_surrounding_chars counts the number of times a character is surrounded by characters from the given surrounding_chars list.

text = "ZZZZZ"
surrounding_chars = ["Z"]
res = check_surrounding_chars(text, surrounding_chars)
# res == 3 because of the following matches
# ZZZZZ
#  ^^^
text = "ABCCBAAAZz"
surrounding_chars = ["Z", "A"]
res = check_surrounding_chars(text, surrounding_chars)
# res == 2 because of the following matches
# ABCCBAAAZz
#       ^^