Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
4727bd1d
Commit
4727bd1d
authored
Jul 2, 2018
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
docs/ure: Document sub(), groups(), span(), start() and end().
parent
79d5e3ab
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/library/ure.rst
+42
-2
42 additions, 2 deletions
docs/library/ure.rst
with
42 additions
and
2 deletions
docs/library/ure.rst
+
42
−
2
View file @
4727bd1d
...
@@ -64,6 +64,22 @@ Functions
...
@@ -64,6 +64,22 @@ Functions
string for first position which matches regex (which still may be
string for first position which matches regex (which still may be
0 if regex is anchored).
0 if regex is anchored).
.. function:: sub(regex_str, replace, string, count=0, flags=0)
Compile *regex_str* and search for it in *string*, replacing all matches
with *replace*, and returning the new string.
*replace* can be a string or a function. If it is a string then escape
sequences of the form ``\<number>`` and ``\g<number>`` can be used to
expand to the corresponding group (or an empty string for unmatched groups).
If *replace* is a function then it must take a single argument (the match)
and should return a replacement string.
If *count* is specified and non-zero then substitution will stop after
this many substitutions are made. The *flags* argument is ignored.
Note: availability of this function depends on `MicroPython port`.
.. data:: DEBUG
.. data:: DEBUG
Flag value, display debug information about compiled expression.
Flag value, display debug information about compiled expression.
...
@@ -80,8 +96,10 @@ Compiled regular expression. Instances of this class are created using
...
@@ -80,8 +96,10 @@ Compiled regular expression. Instances of this class are created using
.. method:: regex.match(string)
.. method:: regex.match(string)
regex.search(string)
regex.search(string)
regex.sub(replace, string, count=0, flags=0)
Similar to the module-level functions :meth:`match` and :meth:`search`.
Similar to the module-level functions :meth:`match`, :meth:`search`
and :meth:`sub`.
Using methods is (much) more efficient if the same regex is applied to
Using methods is (much) more efficient if the same regex is applied to
multiple strings.
multiple strings.
...
@@ -94,9 +112,31 @@ Compiled regular expression. Instances of this class are created using
...
@@ -94,9 +112,31 @@ Compiled regular expression. Instances of this class are created using
Match objects
Match objects
-------------
-------------
Match objects as returned by `match()` and `search()` methods.
Match objects as returned by `match()` and `search()` methods, and passed
to the replacement function in `sub()`.
.. method:: match.group([index])
.. method:: match.group([index])
Return matching (sub)string. *index* is 0 for entire match,
Return matching (sub)string. *index* is 0 for entire match,
1 and above for each capturing group. Only numeric groups are supported.
1 and above for each capturing group. Only numeric groups are supported.
.. method:: match.groups()
Return a tuple containing all the substrings of the groups of the match.
Note: availability of this method depends on `MicroPython port`.
.. method:: match.start([index])
match.end([index])
Return the index in the original string of the start or end of the
substring group that was matched. *index* defaults to the entire
group, otherwise it will select a group.
Note: availability of these methods depends on `MicroPython port`.
.. method:: match.span([index])
Returns the 2-tuple ``(match.start(index), match.end(index))``.
Note: availability of this method depends on `MicroPython port`.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment