emilpmp
emilpmp

Reputation: 1736

Splitting string by '#' followed by a number

I have a string like this 'galore#2 abounding#1 lost#3'. But I need to split this string like this ['galore', 'abounding', 'lost']. Basically the strings should be split by number. I am a newbie in Python programming, any help would be greatly appreciated.

Upvotes: 1

Views: 57

Answers (1)

Rakesh
Rakesh

Reputation: 82765

Using Regex. re.findall

Ex:

import re

s = 'galore#2 abounding#1 lost#3'
print(re.findall(r"[a-z]+(?=\#)", s))

Output:

['galore', 'abounding', 'lost']

Upvotes: 4

Related Questions