matching multiple line string with perl regex and doing a replace

前端 未结 4 2109
孤城傲影
孤城傲影 2021-01-24 00:06

I have a source file where I use a macro to do logging. Typical logging lines look like:

STDOUT_LOG(logDEBUG4) << \"a single line log text\" << aVari         


        
4条回答
  •  Happy的楠姐
    2021-01-24 00:13

    In the end the command that successfully did what I wanted was the following:

    perl -0777pne 's/STDOUT_LOG\((.*?)\)(.*?)<<(.*?);/STDOUT_LOG\(\1\,\2\3\);/gs' sensor.cpp
    

    This is alot a superposition for the answers of "Federico Piazza" and "zdim". You'll notice I prepended the "STDOUT_LOG" bit in the front to really much exactly what I wanted in a large number of source files. I noticed that for correct matching one MUST include the /s operator at the end of the regex , but also add the -0777 flag in the perl executable.

    see perlrun for an explanation of the runtime perl executable flags

提交回复
热议问题