pyxx.strings.strip_matched_brackets#

pyxx.strings.strip_matched_brackets(value: str, max_pairs: int = -1, strip: bool = True, return_num_pairs_removed: bool = False, opening_bracket: str = '(', closing_bracket: str = ')')#

Remove matched leading/trailing brackets from strings

Removes matched brackets from a string (i.e., if a string begins with opening_bracket and the corresponding closing bracket closing_bracket is the last character in the string, the brackets are removed), as well as (optionally) any leading and/or trailing whitespace.

Parameters:
  • value (str) – String from which to remove matched brackets and leading/trailing whitespace (if strip is True)

  • max_pairs (int, optional) – Maximum pairs of matched brackets to remove. Set to -1 to remove an unlimited number of matched brackets (default is -1)

  • strip (bool, optional) – Whether to remove leading and/or trailing whitespace when processing value (default is True)

  • return_num_pairs_removed (bool, optional) – Whether to return the number of pairs of brackets that were removed (default is False)

Returns:

  • str – Input string value with matched brackets removed

  • int – The number of pairs of matched brackets that were removed (returned if and only if return_num_pairs_removed is True)

Notes

If strip is set to False, then matched brackets are removed if and only if the first character in value is opening_bracket and the last character is closing_bracket and they form a matching pair