re not working

MRAB python at mrabarnett.plus.com
Mon Sep 16 22:01:32 EDT 2019


On 2019年09月17日 02:31, CrazyVideoGamez wrote:
> For some reason these are different:
>> pattern = r'[0-9]{4,6}'
>> And
>> pattern2 = r'[0-9][0-9][0-9][0-9]([0-9]){0,2}'
>> And when I try to match them
>> import re
> re.search(pattern, '1234')
>> and
>> import re
> re.search(pattern2, '1234')
>> are different. Help?
>Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> import re
 >>> pattern = r'[0-9]{4,6}'
 >>> pattern2 = r'[0-9][0-9][0-9][0-9]([0-9]){0,2}'
 >>> re.search(pattern, '1234')
<re.Match object; span=(0, 4), match='1234'>
 >>> re.search(pattern2, '1234')
<re.Match object; span=(0, 4), match='1234'>
They look the same to me.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /