In [1]:
import re
In [2]:
s = '012-3456-7890'
In [3]:
print(re.search(r'\d+', s))
In [4]:
m = re.search(r'\d+', s)
In [5]:
print(m.group())
In [6]:
print(type(m.group()))
In [7]:
print(re.findall(r'\d+', s))
In [8]:
print(re.findall('a.*b', 'axyzb'))
In [9]:
print(re.findall('a.*b', 'a---b'))
In [10]:
print(re.findall('a.*b', 'aあいうえおb'))
In [11]:
print(re.findall('a.*b', 'ab'))
In [12]:
print(re.findall('a.+b', 'ab'))
In [13]:
print(re.findall('a.+b', 'axb'))
In [14]:
print(re.findall('a.+b', 'axxxxxxb'))
In [15]:
print(re.findall('a.?b', 'ab'))
In [16]:
print(re.findall('a.?b', 'axb'))
In [17]:
print(re.findall('a.?b', 'axxb'))
In [18]:
print(re.findall('a(.*)b', 'axyzb'))
In [19]:
print(re.findall(r'\(.+\)', 'abc(def)ghi'))
In [20]:
print(re.findall(r'\((.+)\)', 'abc(def)ghi'))
In [21]:
s = 'axb-axxxxxxb'
In [22]:
print(re.findall('a.*b', s))
In [23]:
print(re.findall('a.*?b', s))
In [24]:
print(re.findall('a.+b', s))
In [25]:
print(re.findall('a.+?b', s))
In [26]:
print(re.findall('[abc]x', 'ax-bx-cx'))
In [27]:
print(re.findall('[abc]+', 'abc-aaa-cba'))
In [28]:
print(re.findall('[a-z]+', 'abc-xyz'))
In [29]:
s = 'abc-012-あいうえお'
In [30]:
print(re.findall('[0-9]+', s))
In [31]:
print(re.findall('[a-z]+', s))
In [32]:
print(re.findall('[ぁ-ゟ]+', s))
In [33]:
s = 'abc-def-ghi'
In [34]:
print(re.findall('[a-z]+', s))
In [35]:
print(re.findall('^[a-z]+', s))
In [36]:
print(re.findall('[a-z]+$', s))
In [37]:
s = 'axxxb-012'
In [38]:
print(re.findall('a.*b', s))
In [39]:
print(re.findall(r'\d+', s))
In [40]:
print(re.findall(r'a.*b|\d+', s))
In [41]:
s = 'abc-Abc-ABC'
In [42]:
print(re.findall('[a-z]+', s))
In [43]:
print(re.findall('[A-Z]+', s))
In [44]:
print(re.findall('[a-z]+', s, flags=re.IGNORECASE))