Sometimes, while working with Python strings, we may have to perform a split. Not sometimes, normal one, depending on deliminator but something depending upon programming constructs like elements, numbers, words etc and segregate them. Lets discuss a way in which this task can be solved.
Method : Using
A specific regex can be employed to perform this task. In this we construct regex using different elements like numbers, words punctuations etc.
The original string is : print("geeks"); The splitted string is : ['print', '(', '"', 'geeks', '"', ')', ';']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.