mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
9adb4f0e8c
Reported by fred` at #limnoria. This adds a new message tag applied to all messages SedRegex has seen, in addition to the one for marking messages parsed as a regexp. SedRegex will now look through the message history and check that all messages without the "seen" tag are not in fact a regexp, before marking it as seen so that it doesn't do repeated work.
30 lines
874 B
Python
Executable File
30 lines
874 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import re
|
|
|
|
TAG_SEEN = 'SedRegex.seen'
|
|
TAG_IS_REGEX = 'SedRegex.isRegex'
|
|
|
|
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)
|