Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
MatchObject Class Reference

Public Member Functions

def __init__
 
def start
 
def end
 
def span
 
def groups
 
def group
 
def groupdict
 

Data Fields

 re
 
 string
 
 pos
 
 endpos
 
 regs
 

Detailed Description

Holds a compiled regular expression pattern.

Methods:
start      Return the index of the start of a matched substring.
end        Return the index of the end of a matched substring.
span       Return a tuple of (start, end) of a matched substring.
groups     Return a tuple of all the subgroups of the match.
group      Return one or more subgroups of the match.
groupdict  Return a dictionary of all the named subgroups of the match.

Definition at line 506 of file pre.py.

Constructor & Destructor Documentation

def __init__ (   self,
  re,
  string,
  pos,
  endpos,
  regs 
)

Definition at line 519 of file pre.py.

520  def __init__(self, re, string, pos, endpos, regs):
521  self.re = re
522  self.string = string
523  self.pos = pos
524  self.endpos = endpos
525  self.regs = regs

Member Function Documentation

def end (   self,
  g = 0 
)
end([group=0]) -> int or None

Return the indices of the end of the substring matched by
group; group defaults to zero (meaning the whole matched
substring). Return -1 if group exists but did not contribute
to the match.

Definition at line 542 of file pre.py.

References MatchObject.regs.

543  def end(self, g = 0):
544  """end([group=0]) -> int or None
545 
546  Return the indices of the end of the substring matched by
547  group; group defaults to zero (meaning the whole matched
548  substring). Return -1 if group exists but did not contribute
549  to the match.
550 
551  """
552  if type(g) == type(''):
553  try:
554  g = self.re.groupindex[g]
555  except (KeyError, TypeError):
556  raise IndexError, 'group %s is undefined' % `g`
557  return self.regs[g][1]
def group (   self,
  groups 
)
group([group1, group2, ...]) -> string or tuple

Return one or more subgroups of the match. If there is a
single argument, the result is a single string; if there are
multiple arguments, the result is a tuple with one item per
argument. Without arguments, group1 defaults to zero (i.e. the
whole match is returned). If a groupN argument is zero, the
corresponding return value is the entire matching string; if
it is in the inclusive range [1..99], it is the string
matching the the corresponding parenthesized group. If a group
number is negative or larger than the number of groups defined
in the pattern, an IndexError exception is raised. If a group
is contained in a part of the pattern that did not match, the
corresponding result is None. If a group is contained in a
part of the pattern that matched multiple times, the last
match is returned.

If the regular expression uses the (?P<name>...) syntax, the
groupN arguments may also be strings identifying groups by
their group name. If a string argument is not used as a group
name in the pattern, an IndexError exception is raised.

Definition at line 592 of file pre.py.

References MatchObject.regs, MatchObject.string, and log_faction_ships.tuple.

593  def group(self, *groups):
594  """group([group1, group2, ...]) -> string or tuple
595 
596  Return one or more subgroups of the match. If there is a
597  single argument, the result is a single string; if there are
598  multiple arguments, the result is a tuple with one item per
599  argument. Without arguments, group1 defaults to zero (i.e. the
600  whole match is returned). If a groupN argument is zero, the
601  corresponding return value is the entire matching string; if
602  it is in the inclusive range [1..99], it is the string
603  matching the the corresponding parenthesized group. If a group
604  number is negative or larger than the number of groups defined
605  in the pattern, an IndexError exception is raised. If a group
606  is contained in a part of the pattern that did not match, the
607  corresponding result is None. If a group is contained in a
608  part of the pattern that matched multiple times, the last
609  match is returned.
610 
611  If the regular expression uses the (?P<name>...) syntax, the
612  groupN arguments may also be strings identifying groups by
613  their group name. If a string argument is not used as a group
614  name in the pattern, an IndexError exception is raised.
615 
616  """
617  if len(groups) == 0:
618  groups = (0,)
619  result = []
620  for g in groups:
621  if type(g) == type(''):
622  try:
623  g = self.re.groupindex[g]
624  except (KeyError, TypeError):
625  raise IndexError, 'group %s is undefined' % `g`
626  if g >= len(self.regs):
627  raise IndexError, 'group %s is undefined' % `g`
628  a, b = self.regs[g]
629  if a == -1 or b == -1:
630  result.append(None)
631  else:
632  result.append(self.string[a:b])
633  if len(result) > 1:
634  return tuple(result)
635  elif len(result) == 1:
636  return result[0]
637  else:
638  return ()
def groupdict (   self,
  default = None 
)
groupdict([default=None]) -> dictionary

Return a dictionary containing all the named subgroups of the
match, keyed by the subgroup name. The default argument is
used for groups that did not participate in the match.

Definition at line 639 of file pre.py.

References MatchObject.regs, and MatchObject.string.

640  def groupdict(self, default=None):
641  """groupdict([default=None]) -> dictionary
642 
643  Return a dictionary containing all the named subgroups of the
644  match, keyed by the subgroup name. The default argument is
645  used for groups that did not participate in the match.
646 
647  """
648  dict = {}
649  for name, index in self.re.groupindex.items():
650  a, b = self.regs[index]
651  if a == -1 or b == -1:
652  dict[name] = default
653  else:
654  dict[name] = self.string[a:b]
655  return dict
def groups (   self,
  default = None 
)
groups([default=None]) -> tuple

Return a tuple containing all the subgroups of the match, from
1 up to however many groups are in the pattern. The default
argument is used for groups that did not participate in the
match.

Definition at line 574 of file pre.py.

References MatchObject.regs, MatchObject.string, and log_faction_ships.tuple.

575  def groups(self, default=None):
576  """groups([default=None]) -> tuple
577 
578  Return a tuple containing all the subgroups of the match, from
579  1 up to however many groups are in the pattern. The default
580  argument is used for groups that did not participate in the
581  match.
582 
583  """
584  result = []
585  for g in range(1, self.re._num_regs):
586  a, b = self.regs[g]
587  if a == -1 or b == -1:
588  result.append(default)
589  else:
590  result.append(self.string[a:b])
591  return tuple(result)
def span (   self,
  g = 0 
)
span([group=0]) -> tuple

Return the 2-tuple (m.start(group), m.end(group)). Note that
if group did not contribute to the match, this is (-1,
-1). Group defaults to zero (meaning the whole matched
substring).

Definition at line 558 of file pre.py.

References MatchObject.regs.

559  def span(self, g = 0):
560  """span([group=0]) -> tuple
561 
562  Return the 2-tuple (m.start(group), m.end(group)). Note that
563  if group did not contribute to the match, this is (-1,
564  -1). Group defaults to zero (meaning the whole matched
565  substring).
566 
567  """
568  if type(g) == type(''):
569  try:
570  g = self.re.groupindex[g]
571  except (KeyError, TypeError):
572  raise IndexError, 'group %s is undefined' % `g`
573  return self.regs[g]
def start (   self,
  g = 0 
)
start([group=0]) -> int or None

Return the index of the start of the substring matched by
group; group defaults to zero (meaning the whole matched
substring). Return -1 if group exists but did not contribute
to the match.

Definition at line 526 of file pre.py.

References MatchObject.regs.

527  def start(self, g = 0):
528  """start([group=0]) -> int or None
529 
530  Return the index of the start of the substring matched by
531  group; group defaults to zero (meaning the whole matched
532  substring). Return -1 if group exists but did not contribute
533  to the match.
534 
535  """
536  if type(g) == type(''):
537  try:
538  g = self.re.groupindex[g]
539  except (KeyError, TypeError):
540  raise IndexError, 'group %s is undefined' % `g`
541  return self.regs[g][0]

Field Documentation

endpos

Definition at line 523 of file pre.py.

pos

Definition at line 522 of file pre.py.

re

Definition at line 520 of file pre.py.

regs

Definition at line 524 of file pre.py.

string

Definition at line 521 of file pre.py.


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