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

Data Structures

class  RegexObject
 
class  _Dummy
 
class  MatchObject
 

Functions

def match
 
def search
 
def sub
 
def subn
 
def split
 
def findall
 
def escape
 
def compile
 

Variables

list __all__
 
 I = IGNORECASE
 
 L = LOCALE
 
 M = MULTILINE
 
 S = DOTALL
 
 X = VERBOSE
 
dictionary _cache = {}
 
int _MAXCACHE = 20
 

Function Documentation

def pre.compile (   pattern,
  flags = 0 
)
compile(pattern[, flags]) -> RegexObject

Compile a regular expression pattern into a regular expression
object, which can be used for matching using its match() and
search() methods.

Definition at line 236 of file pre.py.

237 def compile(pattern, flags=0):
238  """compile(pattern[, flags]) -> RegexObject
239 
240  Compile a regular expression pattern into a regular expression
241  object, which can be used for matching using its match() and
242  search() methods.
243 
244  """
245  groupindex={}
246  code=pcre_compile(pattern, flags, groupindex)
247  return RegexObject(pattern, flags, code, groupindex)
248 
249 
250 #
251 # Class definitions
252 #
def pre.escape (   pattern)
escape(string) -> string

Return string with all non-alphanumerics backslashed; this is
useful if you want to match an arbitrary literal string that may
have regular expression metacharacters in it.

Definition at line 220 of file pre.py.

References dospath.join().

221 def escape(pattern):
222  """escape(string) -> string
223 
224  Return string with all non-alphanumerics backslashed; this is
225  useful if you want to match an arbitrary literal string that may
226  have regular expression metacharacters in it.
227 
228  """
229  result = list(pattern)
230  for i in range(len(pattern)):
231  char = pattern[i]
232  if not char.isalnum():
233  if char=='\000': result[i] = '\\000'
234  else: result[i] = '\\'+char
235  return ''.join(result)
def pre.findall (   pattern,
  string 
)
findall(pattern, string) -> list

Return a list of all non-overlapping matches of pattern in
string. If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern has
more than one group. Empty matches are included in the result.

Definition at line 207 of file pre.py.

208 def findall(pattern, string):
209  """findall(pattern, string) -> list
210 
211  Return a list of all non-overlapping matches of pattern in
212  string. If one or more groups are present in the pattern, return a
213  list of groups; this will be a list of tuples if the pattern has
214  more than one group. Empty matches are included in the result.
215 
216  """
217  if type(pattern) == type(''):
218  pattern = _cachecompile(pattern)
219  return pattern.findall(string)
def pre.match (   pattern,
  string,
  flags = 0 
)
match (pattern, string[, flags]) -> MatchObject or None

If zero or more characters at the beginning of string match the
regular expression pattern, return a corresponding MatchObject
instance. Return None if the string does not match the pattern;
note that this is different from a zero-length match.

Note: If you want to locate a match anywhere in string, use
search() instead.

Definition at line 129 of file pre.py.

130 def match(pattern, string, flags=0):
131  """match (pattern, string[, flags]) -> MatchObject or None
132 
133  If zero or more characters at the beginning of string match the
134  regular expression pattern, return a corresponding MatchObject
135  instance. Return None if the string does not match the pattern;
136  note that this is different from a zero-length match.
137 
138  Note: If you want to locate a match anywhere in string, use
139  search() instead.
140 
141  """
142 
143  return _cachecompile(pattern, flags).match(string)
def pre.search (   pattern,
  string,
  flags = 0 
)
search (pattern, string[, flags]) -> MatchObject or None

Scan through string looking for a location where the regular
expression pattern produces a match, and return a corresponding
MatchObject instance. Return None if no position in the string
matches the pattern; note that this is different from finding a
zero-length match at some point in the string.

Definition at line 144 of file pre.py.

145 def search(pattern, string, flags=0):
146  """search (pattern, string[, flags]) -> MatchObject or None
147 
148  Scan through string looking for a location where the regular
149  expression pattern produces a match, and return a corresponding
150  MatchObject instance. Return None if no position in the string
151  matches the pattern; note that this is different from finding a
152  zero-length match at some point in the string.
153 
154  """
155  return _cachecompile(pattern, flags).search(string)
def pre.split (   pattern,
  string,
  maxsplit = 0 
)
split(pattern, string[, maxsplit=0]) -> list of strings

Split string by the occurrences of pattern. If capturing
parentheses are used in pattern, then the text of all groups in
the pattern are also returned as part of the resulting list. If
maxsplit is nonzero, at most maxsplit splits occur, and the
remainder of the string is returned as the final element of the
list.

Definition at line 192 of file pre.py.

193 def split(pattern, string, maxsplit=0):
194  """split(pattern, string[, maxsplit=0]) -> list of strings
195 
196  Split string by the occurrences of pattern. If capturing
197  parentheses are used in pattern, then the text of all groups in
198  the pattern are also returned as part of the resulting list. If
199  maxsplit is nonzero, at most maxsplit splits occur, and the
200  remainder of the string is returned as the final element of the
201  list.
202 
203  """
204  if type(pattern) == type(''):
205  pattern = _cachecompile(pattern)
206  return pattern.split(string, maxsplit)
def pre.sub (   pattern,
  repl,
  string,
  count = 0 
)
sub(pattern, repl, string[, count=0]) -> string

Return the string obtained by replacing the leftmost
non-overlapping occurrences of pattern in string by the
replacement repl. If the pattern isn't found, string is returned
unchanged. repl can be a string or a function; if a function, it
is called for every non-overlapping occurrence of pattern. The
function takes a single match object argument, and returns the
replacement string.

The pattern may be a string or a regex object; if you need to
specify regular expression flags, you must use a regex object, or
use embedded modifiers in a pattern; e.g.
sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'.

The optional argument count is the maximum number of pattern
occurrences to be replaced; count must be a non-negative integer,
and the default value of 0 means to replace all occurrences.

Definition at line 156 of file pre.py.

157 def sub(pattern, repl, string, count=0):
158  """sub(pattern, repl, string[, count=0]) -> string
159 
160  Return the string obtained by replacing the leftmost
161  non-overlapping occurrences of pattern in string by the
162  replacement repl. If the pattern isn't found, string is returned
163  unchanged. repl can be a string or a function; if a function, it
164  is called for every non-overlapping occurrence of pattern. The
165  function takes a single match object argument, and returns the
166  replacement string.
167 
168  The pattern may be a string or a regex object; if you need to
169  specify regular expression flags, you must use a regex object, or
170  use embedded modifiers in a pattern; e.g.
171  sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'.
172 
173  The optional argument count is the maximum number of pattern
174  occurrences to be replaced; count must be a non-negative integer,
175  and the default value of 0 means to replace all occurrences.
176 
177  """
178  if type(pattern) == type(''):
179  pattern = _cachecompile(pattern)
180  return pattern.sub(repl, string, count)
def pre.subn (   pattern,
  repl,
  string,
  count = 0 
)
subn(pattern, repl, string[, count=0]) -> (string, num substitutions)

Perform the same operation as sub(), but return a tuple
(new_string, number_of_subs_made).

Definition at line 181 of file pre.py.

182 def subn(pattern, repl, string, count=0):
183  """subn(pattern, repl, string[, count=0]) -> (string, num substitutions)
184 
185  Perform the same operation as sub(), but return a tuple
186  (new_string, number_of_subs_made).
187 
188  """
189  if type(pattern) == type(''):
190  pattern = _cachecompile(pattern)
191  return pattern.subn(repl, string, count)

Variable Documentation

list __all__
Initial value:
1 = ["match","search","sub","subn","split","findall","escape","compile",
2  "I","L","M","S","X","IGNORECASE","LOCALE","MULTILINE","DOTALL",
3  "VERBOSE","error"]

Definition at line 90 of file pre.py.

dictionary _cache = {}

Definition at line 114 of file pre.py.

int _MAXCACHE = 20

Definition at line 115 of file pre.py.

I = IGNORECASE

Definition at line 103 of file pre.py.

L = LOCALE

Definition at line 104 of file pre.py.

M = MULTILINE

Definition at line 105 of file pre.py.

S = DOTALL

Definition at line 106 of file pre.py.

X = VERBOSE

Definition at line 107 of file pre.py.