In [1]:
import re

In [2]:
p = re.compile('[0123456789]+')
print(p.fullmatch('123'))


<re.Match object; span=(0, 3), match='123'>

In [3]:
p = re.compile('[^0123456789]+')
print(p.fullmatch('123'))


None

In [4]:
print(p.fullmatch('abc'))


<re.Match object; span=(0, 3), match='abc'>

In [5]:
p = re.compile('[0-9]+')
print(p.fullmatch('123'))


<re.Match object; span=(0, 3), match='123'>

In [6]:
# p = re.compile('[9-0]+')
# error: bad character range 9-0 at position 1

In [7]:
p = re.compile('[\u3041-\u309F]+')
print(p.fullmatch('あいうえおぁぃぅぇぉわをん'))


<re.Match object; span=(0, 13), match='あいうえおぁぃぅぇぉわをん'>

In [8]:
p = re.compile('[ぁ-ゟ]+')
print(p.fullmatch('あいうえおぁぃぅぇぉわをん'))


<re.Match object; span=(0, 13), match='あいうえおぁぃぅぇぉわをん'>

In [9]:
print('[\u3041-\u309F]+')


[ぁ-ゟ]+

In [10]:
print(r'[\u3041-\u309F]+')


[\u3041-\u309F]+

In [11]:
print(r'[{}-{}]+'.format('\u3041', '\u309F'))


[ぁ-ゟ]+

In [12]:
p = re.compile('[a-zA-Z]+')
print(p.fullmatch('abcABC'))


<re.Match object; span=(0, 6), match='abcABC'>

In [13]:
p = re.compile('[a-zA-Z\-[\]]+')
print(p.fullmatch('abc-[ABC]'))


<re.Match object; span=(0, 9), match='abc-[ABC]'>

In [14]:
p = re.compile('[a-zA-Z]+')
print(p.findall('abcABCxyzXYZ'))


['abcABCxyzXYZ']

In [15]:
p = re.compile('[a-z]+|[A-Z]+')
print(p.findall('abcABCxyzXYZ'))


['abc', 'ABC', 'xyz', 'XYZ']