0

I'm trying to find a regex for removing everything after the last dot in a file. So far I've found ways to remove all text before the first dot, but I can't seem to find a way to select the end of the file. Could you help me on the way?

Thanks in advance

user2295594
  • 85
  • 2
  • 2
  • 5
  • 2
    `/\.[^.]*?$/`, surely? – Niet the Dark Absol Oct 31 '13 at 15:43
  • 2
    Welcome to Stack Overflow. Please improve your question by posting some [properly formatted](http://stackoverflow.com/editing-help) code you've applied to the problem, all **relevant** error messages exactly as they appear, and whatever samples you're testing against. Also, please include a properly-formatted sample of your **expected output** so folks understand the results you're trying to achieve. – Todd A. Jacobs Oct 31 '13 at 15:44

3 Answers3

22

You can try something like:

\.[^.]*$

to match everything including and after the last dot. If you don't want to include the last dot, then you can use a positive lookbehind:

(?<=\.)[^.]*$
arshajii
  • 127,459
  • 24
  • 238
  • 287
0

Try following regex for search and replace

s/\.[^.]*$/\./
jkshah
  • 11,387
  • 6
  • 35
  • 45
-1

On Bigquery, r'([^.]+).?$' works, if you want to remove the last dot.

Valentin Richer
  • 680
  • 1
  • 12
  • 24