Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70608
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'debug': 0.07; 'subject:bug': 0.07; 'think,': 0.07; 'literal': 0.09; 'parsed': 0.09; 'parsing': 0.09; '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:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'instance:': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:expression': 0.16; 'subject:possible': 0.16; 'surprising': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'input': 0.22; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'possibly': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'chris': 0.29; "we'd": 0.29; 'am,': 0.29; 'character': 0.29; 'raise': 0.29; "doesn't": 0.30; 'matching': 0.30; "i'm": 0.30; 'code': 0.31; 'follows': 0.31; 'yields': 0.31; 'there.': 0.32; 'probably': 0.32; 'regular': 0.32; 'quite': 0.32; 'entirely': 0.33; 'maybe': 0.34; 'something': 0.35; 'definition': 0.35; 'received:84': 0.35; 'but': 0.35; 'whilst': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'should': 0.36; 'being': 0.38; 'expected': 0.38; 'minimum': 0.38; 'to:addr:python-list': 0.38; 'previous': 0.38; 'that,': 0.38; 'expect': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'expression': 0.60; 'negative': 0.60; 'helps': 0.61; 'skip:a 30': 0.61; 'numbers': 0.61; 'times': 0.62; "you've": 0.63; 'show': 0.63; 'maximum': 0.63; 'more': 0.64; '26,': 0.68; 'repeat': 0.74; '2:30': 0.84; 'error;': 0.91 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=MtHc6gqe c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=tLkI8qN_j18A:10 a=zwaHAIf4gx4A:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=iC56nj4HAAAA:8 a=5vRN5rKejUUMnfUYFzEA:9 a=QEXdDO2ut3YA:10 a=hHy4X7uaErEA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Fri, 25 Apr 2014 18:57:23 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: possible bug in re expression? |
| References | <535A8DB5.4090109@chamonix.reportlab.co.uk> <CAPTjJmpeEiMXbhA=kPt6WY31mO_x0C-J49fJdj0ECb+moD=4wQ@mail.gmail.com> |
| In-Reply-To | <CAPTjJmpeEiMXbhA=kPt6WY31mO_x0C-J49fJdj0ECb+moD=4wQ@mail.gmail.com> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| 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.9504.1398448647.18130.python-list@python.org> (permalink) |
| Lines | 74 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1398448647 news.xs4all.nl 2952 [2001:888:2000:d::a6]:47999 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:70608 |
Show key headers only | View raw
On 2014-04-25 17:55, Chris Angelico wrote:
> 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?
>
The DEBUG flag helps to show what's happening:
>>> r = re.compile('.{1,+3}', flags=re.DEBUG)
any None
literal 123
literal 49
max_repeat 1 4294967295
literal 44
literal 51
literal 125
When it's parsing the pattern it's doing this:
. OK, match any character
{ Looks like the start of a quantifier
1 OK, the minimum count
, OK, the maximum count probably follows
+ Error; it looks like the '{' was a literal
Trying again from the brace:
{ Literal
1 Literal
, Literal
+ Repeat the previous item one or more times
3 Literal
} Literal
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: possible bug in re expression? MRAB <python@mrabarnett.plus.com> - 2014-04-25 18:57 +0100
csiph-web