mint.regex - Palamecia/mint GitHub Wiki
Module
load mint.regex
This module provides tools to extend regular expressions capabilities.
Classes
RegexMatch
This class provides a context to access match informations.
Example:
if match = RegexMatch(re.match(str)) {
first = match.capturedText(1)
second = match.capturedText(2)
}
Members
Modifiers | Member | Description |
---|---|---|
- class |
Item | Internal match item structure. |
+ const |
capturedText | Returns the captured text at position index . The text returned for position... |
+ const |
count | Returns the number of captured texts including the whole match. Example: ... |
+ const |
length | Returns the length of the captured text at position index in the original s... |
- final |
matches | Internal match items. |
+ const |
new | Creates a new context for match . If match is an empty match, none is re... |
+ const |
position | Returns the position of the captured text at position index in the original... |
RegexMatch.Item
Internal match item structure.
Members
Modifiers | Member | Description |
---|---|---|
+ final |
length | Match item's length. |
+ final |
matchString | Match item's sub-string. |
+ const |
new | Creates a new match item with the givens str sub-string, pos position in ... |
+ final |
position | Match item's position. |
Descriptions
RegexMatch.Item.length
0
Match item's length.
RegexMatch.Item.matchString
''
Match item's sub-string.
RegexMatch.Item.new
def (self, str, pos, len)
Creates a new match item with the givens str
sub-string, pos
position in text and len
length.
RegexMatch.Item.position
0
Match item's position.
RegexMatch.capturedText
def (self, index)
Returns the captured text at position index
. The text returned for
position 0
is the entire matched string. Each subsequent indexes
returns a string that matched a (capturing) subexpression of the regexp.
Example:
re = /Looking for (\S+) (and (\S+))/
str = 'Looking for this and that'
if match = RegexMatch(re.match(str)) {
match.capturedText(0)
// gives 'Looking for this and that'
match.capturedText(1)
// gives 'this'
match.capturedText(2)
// gives 'and that'
match.capturedText(3)
// gives 'that'
}
RegexMatch.count
def (self)
Returns the number of captured texts including the whole match.
Example:
re = /Looking for (\S+) (and (\S+))/
str = 'Looking for this and that'
if match = RegexMatch(re.match(str)) {
match.count()
// gives 4
}
RegexMatch.length
def (self, index)
Returns the length of the captured text at position index
in the original
string. If index
is 0
, the length of the whole match is returned.
Example:
re = /Looking for (\S+) (and (\S+))/
str = 'Looking for this and that'
if match = RegexMatch(re.match(str)) {
match.length(0)
// gives 25
match.length(1)
// gives 4
match.length(2)
// gives 8
match.length(3)
// gives 4
}
RegexMatch.matches
[]
Internal match items.
RegexMatch.new
def (self, match)
Creates a new context for match
. If match
is an empty match, none
is returned.
RegexMatch.position
def (self, index)
Returns the position of the captured text at position index
in the
original string. If index
is 0
, the position of the whole match is
returned.
Example:
re = /Looking for (\S+) (and (\S+))/
str = 'Looking for this and that'
if match = RegexMatch(re.match(str)) {
match.position(0)
// gives 0
match.position(1)
// gives 12
match.position(2)
// gives 17
match.position(3)
// gives 21
}