Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Match everything before last dot regex

Tags:

regex

text

tcl

I need a regex that will match everything before a last dot in my string. For example, I have text like this: if_blk4.if_blk1.if_blk1 I would like to get the if_blk4.if_blk1.

Thanks!

like image 214
Sasa Stamenkovic Avatar asked Mar 01 '26 23:03

Sasa Stamenkovic


1 Answers

To match everything up to (but not including) the last dot, use a look ahead for a dot:

.*(?=\.)

The greedy quantifier * makes the match include as of the input much as possible, while the look ahead (?=\.) requires the next character in the input to be a dot.

like image 193
Bohemian Avatar answered Mar 03 '26 11:03

Bohemian