Index counting from the last char

2006-05-22 Thread gisleyt
I'd like to use the index-function to retrieve a certain char in a
string, but i need it to start counting from the last char.

E.g. in the string.

Foo-bar, foo foo-bar

I want the latter hyphen to be returned when i do a index for '-'. Is
there any built in function for this, I don't want to reverse every
string just to do this.

-Gisle-

-- 
http://mail.python.org/mailman/listinfo/python-list


regex in python

2006-05-25 Thread gisleyt
I'm trying to compile a perfectly valid regex, but get the error
message:

 r =
re.compile(r'([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*')
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.3/sre.py", line 179, in compile
return _compile(pattern, flags)
  File "/usr/lib/python2.3/sre.py", line 230, in _compile
raise error, v # invalid expression
sre_constants.error: nothing to repeat
>>>

What does this mean? I know that the regex
([^\d]*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*
is valid because i'm able to use it in Regex Coach. But is Python's
regex syntax different that an ordinary syntax?

By the way, i'm using it to normalise strings like:

London|country/uk/region/europe/geocoord/32.3244,42,1221244
to:
London|country/uk/region/europe/geocoord/32.32,42,12

By using \1\2\4 as replace. I'm open for other suggestions to achieve
this!


-Gisle-

-- 
http://mail.python.org/mailman/listinfo/python-list