pyxx.strings.find_matching_bracket¶
- pyxx.strings.find_matching_bracket(value: str, begin: int, opening_bracket: str = '(', closing_bracket: str = ')') int¶
Finds the index of the bracket that forms a matched pair with another bracket at a given index
Finds the “other bracket” that forms a closed pair of matched brackets in a string
value, beginning from the bracket at indexbegin. Note that if the character at indexbeginis an opening bracket, thenvalueis searched in the forward direction (left to right); while if it is a closing bracket, then the search direction is reversed (right to left).- Parameters:
value (str) – String to search for matching brackets
begin (int) – Index in
valuewhere one of the brackets in the matched pair is foundopening_bracket (str, optional) – Character representing opening bracket (default is
'(')closing_bracket (str, optional) – Character representing closing bracket (default is
')')
- Returns:
Returns the index of the matching bracket, or
-1if the bracket at indexbegininvaluedoes not have a matching bracket invalue- Return type:
int
- Raises:
ValueError – If the character at index
begininvalueis not one of:opening_bracketorclosing_bracket