OpenQuizz
Une application de gestion des contenus pédagogiques
Regex Class Reference
Inheritance diagram for Regex:
Collaboration diagram for Regex:

Public Member Functions

def __init__ (self, pattern, flags=0, asGroupList=False, asMatch=False)
 
def parseImpl (self, instring, loc, doActions=True)
 
def parseImplAsGroupList (self, instring, loc, doActions=True)
 
def parseImplAsMatch (self, instring, loc, doActions=True)
 
def __str__ (self)
 
def sub (self, repl)
 
- Public Member Functions inherited from Token
def __init__ (self)
 
- Public Member Functions inherited from ParserElement
def __init__ (self, savelist=False)
 
def copy (self)
 
def setName (self, name)
 
def setResultsName (self, name, listAllMatches=False)
 
def setBreak (self, breakFlag=True)
 
def setParseAction (self, *fns, **kwargs)
 
def addParseAction (self, *fns, **kwargs)
 
def addCondition (self, *fns, **kwargs)
 
def setFailAction (self, fn)
 
def preParse (self, instring, loc)
 
def postParse (self, instring, loc, tokenlist)
 
def tryParse (self, instring, loc)
 
def canParseNext (self, instring, loc)
 
def parseString (self, instring, parseAll=False)
 
def scanString (self, instring, maxMatches=_MAX_INT, overlap=False)
 
def transformString (self, instring)
 
def searchString (self, instring, maxMatches=_MAX_INT)
 
def split (self, instring, maxsplit=_MAX_INT, includeSeparators=False)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def __sub__ (self, other)
 
def __rsub__ (self, other)
 
def __mul__ (self, other)
 
def __rmul__ (self, other)
 
def __or__ (self, other)
 
def __ror__ (self, other)
 
def __xor__ (self, other)
 
def __rxor__ (self, other)
 
def __and__ (self, other)
 
def __rand__ (self, other)
 
def __invert__ (self)
 
def __iter__ (self)
 
def __getitem__ (self, key)
 
def __call__ (self, name=None)
 
def suppress (self)
 
def leaveWhitespace (self)
 
def setWhitespaceChars (self, chars)
 
def parseWithTabs (self)
 
def ignore (self, other)
 
def setDebugActions (self, startAction, successAction, exceptionAction)
 
def setDebug (self, flag=True)
 
def __repr__ (self)
 
def streamline (self)
 
def checkRecursion (self, parseElementList)
 
def validate (self, validateTrace=None)
 
def parseFile (self, file_or_filename, parseAll=False)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
def __req__ (self, other)
 
def __rne__ (self, other)
 
def matches (self, testString, parseAll=True)
 
def runTests (self, tests, parseAll=True, comment='#', fullDump=True, printResults=True, failureTests=False, postParse=None, file=None)
 

Data Fields

 pattern
 
 flags
 
 re
 
 reString
 
 re_match
 
 name
 
 errmsg
 
 mayIndexError
 
 mayReturnEmpty
 
 asGroupList
 
 asMatch
 
 parseImpl
 
 strRepr
 
- Data Fields inherited from ParserElement
 parseAction
 
 failAction
 
 strRepr
 
 resultsName
 
 saveAsList
 
 skipWhitespace
 
 whiteChars
 
 copyDefaultWhiteChars
 
 mayReturnEmpty
 
 keepTabs
 
 ignoreExprs
 
 debug
 
 streamlined
 
 mayIndexError
 
 errmsg
 
 modalResults
 
 debugActions
 
 re
 
 callPreparse
 
 callDuringTry
 
 name
 

Additional Inherited Members

- Static Public Member Functions inherited from ParserElement
def setDefaultWhitespaceChars (chars)
 
def inlineLiteralsUsing (cls)
 
def resetCache ()
 
def enablePackrat (cache_size_limit=128)
 
- Static Public Attributes inherited from ParserElement
 DEFAULT_WHITE_CHARS
 
 verbose_stacktrace
 
 packrat_cache
 
 packrat_cache_lock
 
 packrat_cache_stats
 

Detailed Description

Token for matching strings that match a given regular
expression. Defined with string specifying the regular expression in
a form recognized by the stdlib Python  `re module <https://docs.python.org/3/library/re.html>`_.
If the given regex contains named groups (defined using ``(?P<name>...)``),
these will be preserved as named parse results.

If instead of the Python stdlib re module you wish to use a different RE module
(such as the `regex` module), you can replace it by either building your
Regex object with a compiled RE that was compiled using regex:

Example::

    realnum = Regex(r"[+-]?\d+\.\d*")
    date = Regex(r'(?P<year>\d{4})-(?P<month>\d\d?)-(?P<day>\d\d?)')
    # ref: https://stackoverflow.com/questions/267399/how-do-you-match-only-valid-roman-numerals-with-a-regular-expression
    roman = Regex(r"M{0,4}(CM|CD|D?{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})")

    # use regex module instead of stdlib re module to construct a Regex using
    # a compiled regular expression
    import regex
    parser = pp.Regex(regex.compile(r'[0-9]'))

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  pattern,
  flags = 0,
  asGroupList = False,
  asMatch = False 
)
The parameters ``pattern`` and ``flags`` are passed
to the ``re.compile()`` function as-is. See the Python
`re module <https://docs.python.org/3/library/re.html>`_ module for an
explanation of the acceptable patterns and flags.

Member Function Documentation

◆ __str__()

def __str__ (   self)

Reimplemented from ParserElement.

◆ parseImpl()

def parseImpl (   self,
  instring,
  loc,
  doActions = True 
)

Reimplemented from ParserElement.

◆ parseImplAsGroupList()

def parseImplAsGroupList (   self,
  instring,
  loc,
  doActions = True 
)

◆ parseImplAsMatch()

def parseImplAsMatch (   self,
  instring,
  loc,
  doActions = True 
)

◆ sub()

def sub (   self,
  repl 
)
Return Regex with an attached parse action to transform the parsed
result as if called using `re.sub(expr, repl, string) <https://docs.python.org/3/library/re.html#re.sub>`_.

Example::

    make_html = Regex(r"(\w+):(.*?):").sub(r"<\1>\2</\1>")
    print(make_html.transformString("h1:main title:"))
    # prints "<h1>main title</h1>"

Field Documentation

◆ asGroupList

asGroupList

◆ asMatch

asMatch

◆ errmsg

errmsg

◆ flags

flags

◆ mayIndexError

mayIndexError

◆ mayReturnEmpty

mayReturnEmpty

◆ name

name

◆ parseImpl

parseImpl

◆ pattern

pattern

◆ re

re

◆ re_match

re_match

◆ reString

reString

◆ strRepr

strRepr

The documentation for this class was generated from the following file: