summaryrefslogtreecommitdiff
path: root/docs/library
diff options
context:
space:
mode:
authorJared Hancock <jared.hancock@centeredsolutions.com>2024-03-25 20:58:51 -0500
committerDamien George <damien@micropython.org>2025-08-11 14:11:56 +1000
commit14ccdeb4d7b9b88ab012258e77d3070340fbc3da (patch)
tree5dfddbc202170ecaa12f1d61746442afef938f5b /docs/library
parent485dac783b8ba7b88fdbf28fcdf54eb053cd8ef7 (diff)
extmod/modre: Add support for start- and endpos.
Pattern objects have two additional parameters for the ::search and ::match methods to define the starting and ending position of the subject within the string to be searched. This allows for searching a sub-string without creating a slice. However, one caveat of using the start-pos rather than a slice is that the start anchor (`^`) remains anchored to the beginning of the text. Signed-off-by: Jared Hancock <jared@greezybacon.me>
Diffstat (limited to 'docs/library')
-rw-r--r--docs/library/re.rst14
1 files changed, 12 insertions, 2 deletions
diff --git a/docs/library/re.rst b/docs/library/re.rst
index 19b15d2d2..b8aeefd90 100644
--- a/docs/library/re.rst
+++ b/docs/library/re.rst
@@ -154,8 +154,8 @@ Regex objects
Compiled regular expression. Instances of this class are created using
`re.compile()`.
-.. method:: regex.match(string)
- regex.search(string)
+.. method:: regex.match(string, [pos, [endpos]])
+ regex.search(string, [pos, [endpos]])
regex.sub(replace, string, count=0, flags=0, /)
Similar to the module-level functions :meth:`match`, :meth:`search`
@@ -163,6 +163,16 @@ Compiled regular expression. Instances of this class are created using
Using methods is (much) more efficient if the same regex is applied to
multiple strings.
+ The optional second parameter *pos* gives an index in the string where the
+ search is to start; it defaults to ``0``. This is not completely equivalent
+ to slicing the string; the ``'^'`` pattern character matches at the real
+ beginning of the string and at positions just after a newline, but not
+ necessarily at the index where the search is to start.
+
+ The optional parameter *endpos* limits how far the string will be searched;
+ it will be as if the string is *endpos* characters long, so only the
+ characters from *pos* to ``endpos - 1`` will be searched for a match.
+
.. method:: regex.split(string, max_split=-1, /)
Split a *string* using regex. If *max_split* is given, it specifies