Below is my string pattern,
'YES-HIDETotal Maze LLC.'
& I want to split the above string into below list,
['YES-HIDE', 'Total Maze LLC.']
How can I do this using regex in python?
Edit:
I'd like to split a string on a capital letter next to a capital letter followed by a lowercase letter using re
package
To provide another example
'PLEASE SPLITThis String'
into
['PLEASE SPLIT', 'This String']
I'm trying to give an answer that will help you understanding the problem and work on the solution.
You have a string with capital letters and at some point there is a small letter. You want the string to be split at the position before the first small letter. You can iterate through the string and find the first small letter, remember that position and split the string there.
This is neither regex nor fast, but simple and verbose:
input_string = 'TESTTest'
for pos, letter in enumerate(input_string):
if letter.islower() and letter.isalpha():
split_position = pos-1
break
first_part = input_string[:split_position]
second_part = input_string[split_position:]