Whittle it on down

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Thu May 5 14:27:05 EDT 2016


Steven D'Aprano writes:

> On Fri, 6 May 2016 03:49 am, Jussi Piitulainen wrote:
>
>> Steven D'Aprano writes:
>> 
>>> I get something like this:
>>>
>>> r"(^[A-Z]+$)|(^([A-Z]+[ ]*\&[ ]*[A-Z]+)+$)"
>>>
>>>
>>> but it fails on strings like "AA   &  A &  A". What am I doing wrong?
>> 
>> It cannot split the string as (LETTERS & LETTERS)(LETTERS & LETTERS)
>> when the middle part is just one LETTER. That's something of a
>> misanalysis anyway. I notice that the correct pattern has already been
>> posted at least thrice and you have acknowledged one of them.
>
> Thrice? I've seen Peter's response (he made the trivial and obvious
> simplification of just using A instead of [A-Z], but that was easy to
> understand), and Random832 almost got it, missing only that you need to
> match the entire string, not just a substring. If there was a third
> response, I missed it.

I think I saw another. I may be mistaken.

Random832's pattern is fine. You need to use re.fullmatch with it.

. .



More information about the Python-list mailing list