extract_words1upper

pyhelpers.text.extract_words1upper(x, join_with=None)[source]

Extract 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:
  • x (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 from x where each word starts with an uppercase letter; if join_with is specified, it returns a single string where these words are joined by join_with.

Return type:

list | str

Examples:

>>> from pyhelpers.text import extract_words1upper
>>> extract_words1upper('Network_Waymarks')
['Network', 'Waymarks']
>>> extract_words1upper('NetworkRailRetainingWall', join_with=' ')
'Network Rail Retaining Wall'