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_bracketand the corresponding closing bracketclosing_bracketis 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
stripisTrue)max_pairs (int, optional) – Maximum pairs of matched brackets to remove. Set to
-1to 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 isTrue)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
valuewith matched brackets removedint – The number of pairs of matched brackets that were removed (returned if and only if
return_num_pairs_removedisTrue)
Notes
If
stripis set toFalse, then matched brackets are removed if and only if the first character invalueisopening_bracketand the last character isclosing_bracketand they form a matching pair