Artificial intelligent assistant

add bracket across numbers at only end of each line I have a file having lines as: ram_reg_10/raja_reg_9/raghu_reg_8 abc_reg_4/bcd_reg_5 cad/pqr_reg_91 I want to convert string "_reg_number" into [number] at only last of every line in vi editor. output should be: ram_reg_10/raja_reg_9/raghu[8] abc_reg_4/bcd[5] cad/pqr[91] I tried: :%s?_reg_[0-9]$?\[[0-9]\]?g But it gives: ram_reg_10/raja_reg_9/raghu[[0-9]] abc_reg_4/bcd[[0-9]] cad/pqr_reg_91 how to do it?

In command mode:


:%s/_reg_\([0-9]\+\)$/[\1]/


Here we use `\+` to match one or more group of numbers at the end. So we don't have substitute with lines like `cad/pqr_reg_`.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 7fafa76a4155b3b7c8983ba394cab2ae