StringParser
A convenience class that makes it easy to pull blocks out of strings and whatnot
MatchIterator: MatchIterator
__init__(self, regex: McUtils.Parsers.RegexPatterns.RegexPattern):
parse(self, txt, regex=None, block_handlers=None, dtypes=None, out=None):
Finds a single match for the and applies parsers for the specified regex in txt
txt
:str
a chunk of text to be matched
regex
:RegexPattern
the regex to match in txt
block_handlers
:iterable[callable] | OrderedDict[str: callable]
handlers for the matched blocks in regex – usually comes from regex
dtypes
:iterable[type | StructuredType] | OrderedDict[str: type | StructuredType]
the types of the data that we expect to match – usually comes from regex
out
:None | StructuredTypeArray | iterable[StructuredTypeArray] | OrderedDict[str: StructuredTypeArray]
where to place the parsed out data – usually comes from regex
:returns
:_
parse_all(self, txt, regex=None, num_results=None, block_handlers=None, dtypes=None, out=None):
parse_iter(self, txt, regex=None, num_results=None, block_handlers=None, dtypes=None):
get_regex_block_handlers(regex):
Uses the uncompiled RegexPattern to determine what blocks exist and what handlers they should use
regex
:RegexPattern
:returns
:_
get_regex_dtypes(regex):
Uses the uncompiled RegexPattern to determine which StructuredTypes to return
regex
:RegexPattern
:returns
:_
handler_method(method):
Turns a regular function into a handler method by adding in (and ignoring) the array argument
method
:Any
:returns
:_
load_array(data, dtype='float'):
to_array(data, array=None, append=False, dtype='float', shape=None, pre=None):
A method to take a string or iterable of strings and quickly dump it to a NumPy array of the right dtype (if it can be cast as one)
data
:Any
dtype
:Any
:returns
:_
array_handler(array=None, append=False, dtype='float', shape=None, pre=None):
Returns a handler that uses to_array
dtype
:Any
array
:Any
shape
:Any
:returns
:_