Detail: IndexHierarchy: Accessor Regular Expression

Overview: IndexHierarchy: Accessor Regular Expression

IndexHierarchy.via_re(pattern, flags).match(pos, endpos)
via_re = <function IndexHierarchy.via_re>[source]
InterfaceRe.match(pos=0, endpos=None)[source]

If zero or more characters at the beginning of string match this regular expression return True, else False. Note that this is different from a zero-length match.

Parameters:
  • pos – Gives an index in the string where the search is to start; it defaults to 0.

  • endpos – Limits how far the string will be searched; it will be as if the string is endpos characters long.

>>> ih = sf.IndexHierarchy.from_labels((('qrs ', '4/1/1517'), ('XYZ', '12/31/1517'), ('123', '6/30/1517'), (' wX ', '12/31/2021')))
>>> ih
<IndexHierarchy>
qrs              4/1/1517
XYZ              12/31/1517
123              6/30/1517
 wX              12/31/2021
<<U4>            <<U10>
>>> ih.via_re('[X123]').match()
[[False False]
 [ True  True]
 [ True False]
 [False  True]]
IndexHierarchy.via_re(pattern, flags).fullmatch(pos, endpos)
via_re = <function IndexHierarchy.via_re>[source]
InterfaceRe.fullmatch(pos=0, endpos=None)[source]

If the whole string matches this regular expression, return True, else False. Note that this is different from a zero-length match.

Parameters:
  • pos – Gives an index in the string where the search is to start; it defaults to 0.

  • endpos – Limits how far the string will be searched; it will be as if the string is endpos characters long.

>>> ih = sf.IndexHierarchy.from_labels((('qrs ', '4/1/1517'), ('XYZ', '12/31/1517'), ('123', '6/30/1517'), (' wX ', '12/31/2021')))
>>> ih
<IndexHierarchy>
qrs              4/1/1517
XYZ              12/31/1517
123              6/30/1517
 wX              12/31/2021
<<U4>            <<U10>
>>> ih.via_re('123').fullmatch()
[[False False]
 [False False]
 [ True False]
 [False False]]
IndexHierarchy.via_re(pattern, flags).split(maxsplit)
via_re = <function IndexHierarchy.via_re>[source]
InterfaceRe.split(maxsplit=0)[source]

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 tuple.

Parameters:

maxsplit – If nonzero, at most maxsplit splits occur, and the remainder of the string is returned as the final element of the tuple.

>>> ih = sf.IndexHierarchy.from_labels((('qrs ', '4/1/1517'), ('XYZ', '12/31/1517'), ('123', '6/30/1517'), (' wX ', '12/31/2021')))
>>> ih
<IndexHierarchy>
qrs              4/1/1517
XYZ              12/31/1517
123              6/30/1517
 wX              12/31/2021
<<U4>            <<U10>
>>> ih.via_re('[X123]').split()
[[('qrs ',) ('4/', '/', '5', '7')]
 [('', 'YZ') ('', '', '/', '', '/', '5', '7')]
 [('', '', '', '') ('6/', '0/', '5', '7')]
 [(' w', ' ') ('', '', '/', '', '/', '0', '', '')]]
IndexHierarchy.via_re(pattern, flags).findall(pos, endpos)
via_re = <function IndexHierarchy.via_re>[source]
InterfaceRe.findall(pos=0, endpos=None)[source]

Return all non-overlapping matches of pattern in string, as a tuple of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a tuple of groups; this will be a tuple of tuples if the pattern has more than one group. Empty matches are included in the result.

Parameters:
  • pos – Gives an index in the string where the search is to start; it defaults to 0.

  • endpos – Limits how far the string will be searched; it will be as if the string is endpos characters long.

>>> ih = sf.IndexHierarchy.from_labels((('qrs ', '4/1/1517'), ('XYZ', '12/31/1517'), ('123', '6/30/1517'), (' wX ', '12/31/2021')))
>>> ih
<IndexHierarchy>
qrs              4/1/1517
XYZ              12/31/1517
123              6/30/1517
 wX              12/31/2021
<<U4>            <<U10>
>>> ih.via_re('[X123]').findall()
[[() ('1', '1', '1')]
 [('X',) ('1', '2', '3', '1', '1', '1')]
 [('1', '2', '3') ('3', '1', '1')]
 [('X',) ('1', '2', '3', '1', '2', '2', '1')]]
IndexHierarchy.via_re(pattern, flags).sub(repl, count)
via_re = <function IndexHierarchy.via_re>[source]
InterfaceRe.sub(repl, count=0)[source]

Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern is not found, the string is returned unchanged.

Parameters:
  • repl – A string or a function; if it is a string, any backslash escapes in it are processed.

  • count – The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. If omitted or zero, all occurrences will be replaced.

>>> ih = sf.IndexHierarchy.from_labels((('qrs ', '4/1/1517'), ('XYZ', '12/31/1517'), ('123', '6/30/1517'), (' wX ', '12/31/2021')))
>>> ih
<IndexHierarchy>
qrs              4/1/1517
XYZ              12/31/1517
123              6/30/1517
 wX              12/31/2021
<<U4>            <<U10>
>>> ih.via_re('[X123]').sub('==')
[['qrs ' '4/==/==5==7']
 ['==YZ' '====/====/==5==7']
 ['======' '6/==0/==5==7']
 [' w== ' '====/====/==0====']]
IndexHierarchy.via_re(pattern, flags).subn(repl, count)
via_re = <function IndexHierarchy.via_re>[source]
InterfaceRe.subn(repl, count=0)[source]

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

Parameters:
  • repl – A string or a function; if it is a string, any backslash escapes in it are processed.

  • count – The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. If omitted or zero, all occurrences will be replaced.

>>> ih = sf.IndexHierarchy.from_labels((('qrs ', '4/1/1517'), ('XYZ', '12/31/1517'), ('123', '6/30/1517'), (' wX ', '12/31/2021')))
>>> ih
<IndexHierarchy>
qrs              4/1/1517
XYZ              12/31/1517
123              6/30/1517
 wX              12/31/2021
<<U4>            <<U10>
>>> ih.via_re('[X123]').subn('==', 1)
[[('qrs ', 0) ('4/==/1517', 1)]
 [('==YZ', 1) ('==2/31/1517', 1)]
 [('==23', 1) ('6/==0/1517', 1)]
 [(' w== ', 1) ('==2/31/2021', 1)]]

IndexHierarchy: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Selector | Iterator | Operator Binary | Operator Unary | Accessor Values | Accessor Datetime | Accessor String | Accessor Transpose | Accessor Regular Expression | Accessor Hashlib | Accessor Type Clinic