[Tutor] finding special character string
Kent Johnson
kent37 at tds.net
Mon Jun 2 01:58:54 CEST 2008
On Sun, Jun 1, 2008 at 2:04 PM, Marilyn Davis <marilyn at deliberate.com> wrote:
> On Sun, June 1, 2008 10:30 am, Alan Gauld wrote:
>
>> "Kent Johnson" <kent37 at tds.net> wrote
>>
>>
>>> Assuming the strings are non-overlapping, i.e. the closing "." of
>>> one string is not the opening "." of another, you can find them all with
>>> import re re.findall(r'\..*?\.', text)
>>
>> Hmm, my regex hopelessness comes to the fore again.
>> Why a *?
>> I would probably have guessed the pattern to be
>>
>>
>> \..+?\.
Mine will find two adjacent periods with no intervening text, yours
won't. Whether this makes any difference to the OP, or which is
correct, I don't know.
> This little program includes a function to test regular expressions. I
> find it helpful and I give it to students. I think such programs exist on
> the net.
I am always surprised at how many regex testers there are, because a
simple tester comes with Python. It is called redemo.py; look for it
in the Tools/scripts or bin/ directory installed with Python. On my
Mac it is at /Library/Frameworks/Python.framework/Versions/2.5/bin/redemo.py.
Kent
More information about the Tutor
mailing list