Created
December 14, 2023 21:54
-
-
Save adamsilkey/9a243427c9645d00505cca08e27a931b to your computer and use it in GitHub Desktop.
Adding pos/endpos to re
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
diff --git a/__init__.py b/__init__.py | |
index 4515650..14140b2 100644 | |
--- a/__init__.py | |
+++ b/__init__.py | |
@@ -125,6 +125,7 @@ import enum | |
from . import _compiler, _parser | |
import functools | |
import _sre | |
+import sys | |
# public symbols | |
@@ -161,20 +162,20 @@ error = _compiler.error | |
# -------------------------------------------------------------------- | |
# public interface | |
-def match(pattern, string, flags=0): | |
+def match(pattern, string, flags=0, pos=0, endpos=sys.maxsize): | |
"""Try to apply the pattern at the start of the string, returning | |
a Match object, or None if no match was found.""" | |
- return _compile(pattern, flags).match(string) | |
+ return _compile(pattern, flags).match(string, pos=pos, endpos=endpos) | |
-def fullmatch(pattern, string, flags=0): | |
+def fullmatch(pattern, string, flags=0, pos=0, endpos=sys.maxsize): | |
"""Try to apply the pattern to all of the string, returning | |
a Match object, or None if no match was found.""" | |
- return _compile(pattern, flags).fullmatch(string) | |
+ return _compile(pattern, flags).fullmatch(string, pos=pos, endpos=endpos) | |
-def search(pattern, string, flags=0): | |
+def search(pattern, string, flags=0, pos=0, endpos=sys.maxsize): | |
"""Scan through string looking for a match to the pattern, returning | |
a Match object, or None if no match was found.""" | |
- return _compile(pattern, flags).search(string) | |
+ return _compile(pattern, flags).search(string, pos=pos, endpos=endpos) | |
def sub(pattern, repl, string, count=0, flags=0): | |
"""Return the string obtained by replacing the leftmost | |
@@ -206,7 +207,7 @@ def split(pattern, string, maxsplit=0, flags=0): | |
of the list.""" | |
return _compile(pattern, flags).split(string, maxsplit) | |
-def findall(pattern, string, flags=0): | |
+def findall(pattern, string, flags=0, pos=0, endpos=sys.maxsize): | |
"""Return a list of all non-overlapping matches in the string. | |
If one or more capturing groups are present in the pattern, return | |
@@ -214,14 +215,14 @@ def findall(pattern, string, flags=0): | |
has more than one group. | |
Empty matches are included in the result.""" | |
- return _compile(pattern, flags).findall(string) | |
+ return _compile(pattern, flags).findall(string, pos=pos, endpos=endpos) | |
-def finditer(pattern, string, flags=0): | |
+def finditer(pattern, string, flags=0, pos=0, endpos=sys.maxsize): | |
"""Return an iterator over all non-overlapping matches in the | |
string. For each match, the iterator returns a Match object. | |
Empty matches are included in the result.""" | |
- return _compile(pattern, flags).finditer(string) | |
+ return _compile(pattern, flags).finditer(string, pos=pos, endpos=endpos) | |
def compile(pattern, flags=0): | |
"Compile a regular expression pattern, returning a Pattern object." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yes