当前位置: 动力学知识库 > 问答 > 编程问答 >

python - 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.

网友答案:

I think you want

re.findall('^[^a-zA-Z]*(.*)', str)
网友答案:

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(.*)$
分享给朋友:
您可能感兴趣的文章:
随机阅读: