egidra
egidra

Reputation: 9087

Only allow alphabetical characters at the beginning of a string?

I want to grab the start of the first alphabetical characters at the beginning of the string:

||hello there -> hello there
((hello there -> hello there

I am using this code:

str = re.findall('^[^a-zA-Z]+(.*?)', str)

str gives me an array of two strings, the first string which is a blank string.

Upvotes: 1

Views: 182

Answers (2)

Toto
Toto

Reputation: 91428

To be unicode compatible, use \pL wich means a letter.

^\pL

This regex ensure you that you have at least one letter at the begining of the string.

If you want to capture the rest of the string:

^\pL(.*)$

Upvotes: 0

Daniel Lubarov
Daniel Lubarov

Reputation: 7924

I think you want

re.findall('^[^a-zA-Z]*(.*)', str)

Upvotes: 2

Related Questions