Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python regex matching all but last occurrence

So I have expression such as "./folder/thisisa.test/file.cxx.h" How do I substitute/remove all the "." but the last dot?

like image 835
landocalrissian Avatar asked Apr 24 '13 22:04

landocalrissian


1 Answers

To match all but the last dot with a regex:

'\.(?=[^.]*\.)'

Using a lookahead to check that's there another dot after the one we found (the lookahead's not part of the match).

like image 166
Loamhoof Avatar answered Sep 18 '22 03:09

Loamhoof