split_on_uppercase¶
- pyhelpers.text.split_on_uppercase(input_text, join_with=None)[source]¶
Extracts words from a string by splitting it at occurrences of uppercase letters.
This function takes a string and splits it into individual words wherever an uppercase letter is encountered. Optionally, it can join these words back into a single string using a specified delimiter.
- Parameters:
input_text (str) – Input text containing a number of words each starting with an uppercase letter.
join_with (str | None) – Optional delimiter used to join the extracted words into a single string; defaults to
None
.
- Returns:
If
join_with=None
, the function returns a list of words extracted frominput_text
where each word starts with an uppercase letter; ifjoin_with
is specified, it returns a single string where these words are joined byjoin_with
.- Return type:
list | str
Examples:
>>> from pyhelpers.text import split_on_uppercase >>> split_on_uppercase('Network_Waymarks') ['Network', 'Waymarks'] >>> split_on_uppercase('NetworkRailRetainingWall', join_with=' ') 'Network Rail Retaining Wall' >>> split_on_uppercase('BCRRE_Projects') ['BCRRE', 'Projects']