JLU5-SupyPlugins/SedRegex/constants.py
James Lu 866875ec5d SedRegex: allow matching text with the trailing suffix missing
Closes https://github.com/jlu5/SupyPlugins/issues/91

Also add test cases for issues described in https://github.com/jlu5/SupyPlugins/issues/59 - text after the trailing separator should be ignored unless its a regex flag.
2020-03-22 21:12:40 -07:00

27 lines
812 B
Python
Executable File

#!/usr/bin/env python3
import re
SED_REGEX = re.compile(
# This part matches an optional nick followed by ":" or ",", used to direct replacement
# at a particular user.
r"^(?:(?P<nick>.+?)[:,] )?"
# Match and save the delimiter (any one symbol) as a named group
r"s(?P<delim>[^\w\s])"
# Match the pattern to replace, which can be any string up to the first instance of the delimiter
r"(?P<pattern>(?:(?!(?P=delim)).)*)(?P=delim)"
# Ditto with the replacement
r"(?P<replacement>(?:(?!(?P=delim)).)*)"
# Optional final delimiter plus flags at the end
r"(?:(?P=delim)(?P<flags>[a-z]*))?"
)
if __name__ == '__main__':
print("This is the full regex used by the plugin; paste it into your favourite regex tester "
"for debugging:")
print(SED_REGEX)