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 index begin. Note that if the character at index begin is an opening bracket, then value is 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 value where one of the brackets in the matched pair is found

  • opening_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 -1 if the bracket at index begin in value does not have a matching bracket in value

Return type:

int

Raises:

ValueError – If the character at index begin in value is not one of: opening_bracket or closing_bracket