-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SedRegex: allow matching text with the trailing suffix missing
Closes #91 Also add test cases for issues described in #59 - text after the trailing separator should be ignored unless its a regex flag.
- Loading branch information
Showing
4 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters