[issue42550] re库匹配问题

2020-12-02 Thread ye andy


Change by ye andy :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

https://docs.python.org/3/howto/regex.html#more-metacharacters

$
Matches at the end of a line, which is defined as either the end of the string, 
or any location followed by a newline character.

\Z
Matches only at the end of the string.

>>> eth_re = re.compile(r'^0x[0-9a-fA-F]{40}\Z')
>>> print(eth_re.match(a))
None
>>> eth_re = re.compile(r'^0x[0-9a-fA-F]{40}$')
>>> print(eth_re.match(a))


You can also use re.DEBUG to see the difference


>>> re.match(r'^0x[0-9a-fA-F]{40}$', a, re.DEBUG)
AT AT_BEGINNING
LITERAL 48
LITERAL 120
MAX_REPEAT 40 40
  IN
RANGE (48, 57)
RANGE (97, 102)
RANGE (65, 70)
AT AT_END

 0. INFO 4 0b0 42 42 (to 5)
 5: AT BEGINNING
 7. LITERAL 0x30 ('0')
 9. LITERAL 0x78 ('x')
11. REPEAT_ONE 16 40 40 (to 28)
15.   IN 11 (to 27)
17. CHARSET [0x, 0x03ff, 0x007e, 0x007e, 0x, 
0x, 0x, 0x]
26. FAILURE
27:   SUCCESS
28: AT END
30. SUCCESS



>>> re.match(r'^0x[0-9a-fA-F]{40}\Z', a, re.DEBUG)
AT AT_BEGINNING
LITERAL 48
LITERAL 120
MAX_REPEAT 40 40
  IN
RANGE (48, 57)
RANGE (97, 102)
RANGE (65, 70)
AT AT_END_STRING

 0. INFO 4 0b0 42 42 (to 5)
 5: AT BEGINNING
 7. LITERAL 0x30 ('0')
 9. LITERAL 0x78 ('x')
11. REPEAT_ONE 16 40 40 (to 28)
15.   IN 11 (to 27)
17. CHARSET [0x, 0x03ff, 0x007e, 0x007e, 0x, 
0x, 0x, 0x]
26. FAILURE
27:   SUCCESS
28: AT END_STRING
30. SUCCESS

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread ye andy


ye andy  added the comment:

Okay, I just thought it was weird

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread hongweipeng


hongweipeng  added the comment:

Maybe you need use `eth_re.match(a, re.MULTILINE)` or `eth_re.fullmatch(a)` .

--
nosy: +hongweipeng

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread ye andy


ye andy  added the comment:

My regulus requires the beginning of 0x, the end of 0-9A-fa-f, my ending \n, he 
also shows success, my expected result is failure, I wrote the problem?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread ye andy


ye andy  added the comment:

My regex requires ending with 0-9a-fa-f, and I now end with a line break, which 
in theory should not work. Why did it work?

--
nosy:  -Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

Maybe you're looking for re.fullmatch:

https://docs.python.org/3/library/re.html#re.fullmatch

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread ye andy


ye andy  added the comment:

What I mean by that is that the regex That I wrote should match successfully is 
a 42-bit string, but it is also successful when we add more newlines

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread Ma Lin


Ma Lin  added the comment:

This issue can be closed.

'0x'  2
'd26935a5ee4cd542e8a3a7e74fb7a99855975b59'  40
'\n'  1

2+40+1 = 43

--
nosy: +malin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42550] re库匹配问题

2020-12-02 Thread ye andy

New submission from ye andy :

import re
a = """0xd26935a5ee4cd542e8a3a7e74fb7a99855975b59\n"""

eth_re = re.compile(r'^0x[0-9a-fA-F]{40}$')

print(eth_re.match(a))
print(len(a)) # 长度43

--
components: Library (Lib)
messages: 382367
nosy: andy.ye.jx
priority: normal
severity: normal
status: open
title: re库匹配问题
type: security
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com