How to use regex to indent code in notepad++

前端 未结 2 718
再見小時候
再見小時候 2021-01-26 01:45

for example I have the following code

Module MPI
    Use MPI
    !
! MPI info
    If (true) Then
        Print *, \'\'
! empty line 1
! empty line 2
    End If
          


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-26 01:51

    Since the engine is already passed on a comment line to indent it, I think it is impossible to use the same entire edited line for the next match to get the number of spaces. So I think you have to repeat the same replacement more times. Try with:

    ^(\s*)([^!\s].*?\r\n(\1\!.*?\r\n)*)\s*\!
    

    always replacing it with $1$2$1!.

    Like I said in the comment, if you have at most N consecutive comment lines, you will click on the "replace all" button N times

提交回复
热议问题