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.
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to