ure – simple regular expressions¶
This module implements a subset of the corresponding CPython module,
as described below. For more information, refer to the original
CPython documentation: re.
This module implements regular expression operations. Regular expression
syntax supported is a subset of CPython re module (and actually is
a subset of POSIX extended regular expressions).
Supported operators are:
'.'- Match any character.
'[]'- Match set of characters. Individual characters and ranges are supported.
'^'
'$'
'?'
'*'
'+'
'??'
'*?'
'+?'
'|'
'()'- Grouping. Each group is capturing (a substring it captures can be accessed
with
match.group()method).
Counted repetitions ({m,n}), more advanced assertions, named groups,
etc. are not supported.
Functions¶
-
ure.match(regex_str, string)¶ Compile regex_str and match against string. Match always happens from starting position in a string.
-
ure.search(regex_str, string)¶ Compile regex_str and search it in a string. Unlike
match, this will search string for first position which matches regex (which still may be 0 if regex is anchored).
-
ure.DEBUG¶ Flag value, display debug information about compiled expression.
Regex objects¶
Compiled regular expression. Instances of this class are created using
ure.compile().
-
regex.match(string)¶ -
regex.search(string)¶ Similar to the module-level functions
match()andsearch(). Using methods is (much) more efficient if the same regex is applied to multiple strings.
-
regex.split(string, max_split=-1)¶ Split a string using regex. If max_split is given, it specifies maximum number of splits to perform. Returns list of strings (there may be up to max_split+1 elements if it’s specified).