Can a Regex Return the Number of the Line where the Match is Found?

后端 未结 3 1015
挽巷
挽巷 2020-12-10 06:44

In a text editor, I want to replace a given word with the number of the line number on which this word is found. Is this is possible with Regex?

3条回答
  •  抹茶落季
    2020-12-10 07:12

    Because you didn't specify which text editor, in vim it would be:

    :%s/searched_word/\=printf('%-4d', line('.'))/g (read more)

    But as somebody mentioned it's not a question for SO but rather Super User ;)

提交回复
热议问题