"Kemp Randy-W18971" <Randy.L.Kemp at motorola.com> wrote in message news:mailman.986239804.14212.python-list at python.org... > Alex: > I tried your suggestion, and I am close, but not quite. What is happening with the number split? [snip] > number = re.compile(r'\d+\.?d*') As I see was pointed out already, you omitted a \ right after the ?. Nobody ever said regular expression syntax is _nice_ or forgiving!-) However, I still suspect re's are the simplest tool for your job (which I haven't seen precisely specified yet -- for example, do you want 'numbers' to include an optional leading sign, a trailing exponent, or...?). The alternatives require you to use other tools to identify runs of contiguous digits, then look at non-digits right before and after digits (and right between runs, if you need to pick up a decimal point as a part of a 'number') to pick up various possible non-digit 'decorations'. Re's offer compact ways to express this kind of things, although of course they do not obviate the need to specify very completely and precisely what you want to happen in various anomalous cases -- e.g., say your text has the line foo 23.45.67 bar what number or numbers should be extracted from this line? The above re, when corrected, will parse it as two numbers: 23.45 67 but IS this OK for your application, or can you somehow guarantee that no such anomaly will ever possibly occur...? Alex
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4