[issue35146] Bad Regular Expression Broke re.findall()

2018-11-02 Thread Dan Boxall


New submission from Dan Boxall :

Hi, I'm new to regular expressions and while playing around with them I tried 
this:

>>> rex = '*New Revision:.* ([0-9]+)'
>>> re.findall(rex, text)

and got this:

Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Python\Python37\lib\re.py", line 223, in findall
return _compile(pattern, flags).findall(string)
  File "C:\Python\Python37\lib\re.py", line 286, in _compile
p = sre_compile.compile(pattern, flags)
  File "C:\Python\Python37\lib\sre_compile.py", line 764, in compile
p = sre_parse.parse(p, flags)
  File "C:\Python\Python37\lib\sre_parse.py", line 930, in parse
p = _parse_sub(source, pattern, flags & SRE_FLAG_VERBOSE, 0)
  File "C:\Python\Python37\lib\sre_parse.py", line 426, in _parse_sub
not nested and not items))
  File "C:\Python\Python37\lib\sre_parse.py", line 651, in _parse
source.tell() - here + len(this))
re.error: nothing to repeat at position 0

--
components: Regular Expressions
messages: 329130
nosy: Callipygean, ezio.melotti, mrabarnett
priority: normal
severity: normal
status: open
title: Bad Regular Expression Broke re.findall()
versions: Python 3.7

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



[issue35146] Bad Regular Expression Broke re.findall()

2018-11-02 Thread Dan Boxall


Dan Boxall  added the comment:

Thank you.  I realised that and if I put a dot in front it worked fine.
But it should not break the function, so they will surely want to fix the
bug?

Kind regards,
Dan Boxall

On Fri, 2 Nov 2018 at 13:56, Windson Yang  wrote:

>
> Windson Yang  added the comment:
>
> The last line "re.error: nothing to repeat at position 0" shows that you
> should not put raw * as the first element, use \* instead.
>
> --
> nosy: +Windson Yang
>
> ___
> Python tracker 
> <https://bugs.python.org/issue35146>
> ___
>

--

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



[issue35146] Bad Regular Expression Broke re.findall()

2018-11-02 Thread Dan Boxall


Dan Boxall  added the comment:

Yes I realised that, as I said earlier.  But it could say, "Invalid regular
expression" and not produce ten lines of error messages.

On Fri, 2 Nov 2018 at 14:21, Steven D'Aprano  wrote:

>
> Steven D'Aprano  added the comment:
>
> This is not a bug in Python, it is an invalid (broken) regular expression.
> There is nothing that the interpreter or the regular expression engine can
> do, because you are telling it to do something that makes no sense. What do
> you expect findall to find, if you ask it to find something nonsensical?
>
> You say:
>
> "repeat this pattern any number of times"
>
> but there is no "this pattern" to be repeated. You are asking for
> something impossible. The only legitimate response is to report back that
> the regular expression is invalid and cannot be compiled, and fail
> immediately.
>
> --
> nosy: +steven.daprano
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> ___
> Python tracker 
> <https://bugs.python.org/issue35146>
> ___
>

--

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