| Store | Cart

regular expression

From: Paul McGuire <ptm...@austin.rr.com>
26 Mar 2005 23:05:33 -0800
Aaron -

Here's a pyparsing approach (requires latest 1.3 pyparsing version).
It may not be as terse or fast as your regexp, but it may be easier to
maintain.

By defining floatNum ahead of DOT in the scanner definition, you
specify the dot-containing expressions that you do *not* want to have
dots converted to colons.

-- Paul

===================
from pyparsing import Word,Literal,replaceWith, Combine, nums

DOT = Literal(".").setParseAction( replaceWith(":") )
floatNum = Combine( Word(nums) + "." + Word(nums) )

scanner = floatNum | DOT

testdata = "'375 mi. south of U.C.B is 3.4 degrees warmer."

print scanner.transformString( testdata )
===================
prints out:
'375 mi: south of U:C:B is 3.4 degrees warmer:

Recent Messages in this Thread
aaron Mar 26, 2005 02:07 am
Bengt Richter Mar 26, 2005 04:30 am
Peter Hansen Mar 26, 2005 04:54 am
Bengt Richter Mar 26, 2005 07:41 am
Peter Hansen Mar 26, 2005 11:53 am
Paul McGuire Mar 27, 2005 07:05 am
Messages in this thread