Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

match last integer from behind

Tags:

regex

i have those strings

hello,world,1.fin
hello,world,start11.fin
hello,world,start11,then,end22.fin
hello,world,111,then,222,then,end333.fin
hello,world,111,then,222,then,end333threes.fin
hello,world,111,then,222,then,end333threes.fin444

and i need to match the endings numbers only before the . and after world, and i expect to get

1
11
22
333
333
333

i tried this but it does not match the last case ,world,.*?(\d+)\. link then i tried this but it only get from begin ,world,.*?(\d+).*\. link

.fin is not static and it does change randomly to .fin444 or .444

like image 764
yvgwxgtyowvaiqndwo Avatar asked Nov 19 '25 17:11

yvgwxgtyowvaiqndwo


1 Answers

This should work

,world,.*?(\d+)[^\d]*\.

See https://regex101.com/r/ilIsJb/1

like image 72
Nikita Chayka Avatar answered Nov 21 '25 08:11

Nikita Chayka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!