Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the regular expression in Python that match ASCII alphabets only? [duplicate]

Tags:

python

regex

I use the regular expression which matches both alphabets and digits.

prog = re.compile(r'^\w+$')

How can I just match ASCII alphabets only?

like image 424
Kintarō Avatar asked May 01 '13 04:05

Kintarō


People also ask

What does ?= Mean in regular expression?

?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).

What does the regular expression '[ a za z ]' match?

For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter.

What is the regex for special characters?

Special Regex Characters: These characters have special meaning in regex (to be discussed below): . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ . Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "."

What is the regular expression matching one or more specific characters?

The character + in a regular expression means "match the preceding character one or more times". For example A+ matches one or more of character A. The plus character, used in a regular expression, is called a Kleene plus .


1 Answers

You must replace \w by [a-zA-Z]

like image 170
Casimir et Hippolyte Avatar answered Sep 28 '22 10:09

Casimir et Hippolyte