mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
485dac783b
commit
14ccdeb4d7
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user