Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #70603

Re: possible bug in re expression?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'subject:bug': 0.07; 'think,': 0.07; 'parsed': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'bug': 0.12; 'translation': 0.12; '2.7': 0.14; 'question.': 0.14; '"":': 0.16; 'brace': 0.16; 'does,': 0.16; 'dot,': 0.16; 'expected,': 0.16; 'extraneous': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instance:': 0.16; 'subject:expression': 0.16; 'subject:possible': 0.16; 'surprising': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'input': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; "we'd": 0.29; 'am,': 0.29; 'character': 0.29; 'raise': 0.29; "doesn't": 0.30; 'matching': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'yields': 0.31; 'there.': 0.32; 'regular': 0.32; 'quite': 0.32; 'entirely': 0.33; 'maybe': 0.34; 'something': 0.35; 'definition': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'whilst': 0.36; 'subject:?': 0.36; 'should': 0.36; 'being': 0.38; 'expected': 0.38; 'that,': 0.38; 'expect': 0.39; 'sure': 0.39; 'how': 0.40; 'expression': 0.60; 'negative': 0.60; 'skip:a 30': 0.61; 'numbers': 0.61; "you've": 0.63; '26,': 0.68; '2:30': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=kuY+5gUAuqF/d5uxvUdEbIdIBTG6aQ4OmIkRUuA7rd0=; b=wuGU/KCC08b2vKtDGqDK3s2OhH5nTywiQ67BQ5OR348ZEYxhStH31po83g10QuTFaJ AW/KqbEkj5YMR5UM4QQbwdeZxweVnrGO8n0usixArCs92ksF/3D7YnHY/JQd2lvS22+R N7sLzsB57rW/7LKnvxlp86vQNOCqknOMd1z3pYMiwAVLp/zCXodjDXHP0ItO4VR1Udj5 kD60wWLscSo6rGrYSO8Ed07nbTfdVXDdZKi9Cqabvig76BmLGM+kogRWcFIQueniU6dV 2TBjtgabWxESDfjIRtj3dCNV1hhTkjBpPt67FD8eGvFQV5T2ptsnw/NcYa2gHg5T1eDL /UGw==
MIME-Version 1.0
X-Received by 10.58.220.161 with SMTP id px1mr7648534vec.13.1398444909272; Fri, 25 Apr 2014 09:55:09 -0700 (PDT)
In-Reply-To <535A8DB5.4090109@chamonix.reportlab.co.uk>
References <535A8DB5.4090109@chamonix.reportlab.co.uk>
Date Sat, 26 Apr 2014 02:55:09 +1000
Subject Re: possible bug in re expression?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9499.1398444917.18130.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1398444917 news.xs4all.nl 2963 [2001:888:2000:d::a6]:54882
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70603

Show key headers only | View raw


On Sat, Apr 26, 2014 at 2:30 AM, Robin Becker <robin@reportlab.com> wrote:
> Whilst translating some javascript code I find that this
>
> A=re.compile('.{1,+3}').findall(p)
>
> doesn't give any error, but doesn't manage to find the strings in p that I
> want len(A)==>0, the correct translation should have been
>
> A=re.compile('.{1,3}').findall(p)
>
> which works fine.
>
> should
>
> re.compile('.{1,+3}')
>
> raise an error? It doesn't on python 2.7 or 3.3.

I would say the surprising part is that your js code doesn't mind an
extraneous character in the regex. In a brace like that, negative
numbers have no meaning, so I would expect the definition of the regex
to look for digits, not "anything that can be parsed as a number". So
you've uncovered a bug in your code that just happened to work in js.

Should it raise an error? Good question. Quite possibly it should,
unless that has some other meaning that I'm not familiar with. Do you
know how it's being interpreted? I'm not entirely sure what you mean
by "len(A)==>0", as ==> isn't an operator in Python or JS. Best way to
continue, I think, would be to use regular expression matching (rather
than findall'ing) and something other than dot, and tabulate input
strings, expected result (match or no match), what JS does, and what
Python does. For instance:

Regex: "^a{1,3}$"

"": Not expected, not Python
"a": Expected, Python
"aa": Expected, Python
"aaa": Expected, Python
"aaaa": Not expected, not Python

Just what we'd expect. Now try the same thing with the plus in there.
I'm finding that none of the above strings yields a match. Maybe
there's something else being matched?

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: possible bug in re expression? Chris Angelico <rosuav@gmail.com> - 2014-04-26 02:55 +1000

csiph-web