当前位置: 动力学知识库 > 问答 > 编程问答 >

sed - regex expression that substitutes "\\n" to '\n'

问题描述:

I need a regex expression that substitutes \\n in a source code written in C to \n.

If:

  1. it is NOT in a function call.

    Example:

    func("str", 1, &addrs); \\n printf("hello");func("str", 1, &addrs); \n printf("hello");

  2. it is NOT in a string

    Example:

    "hello" \\n "there";"hello" \n "there"

As to why I have stray \\n in my code I don't want to say. I just wanna get rid of them.

网友答案:

If I understood correctly something like func("str\\ntest") should stay as is and not be replaced.

Given that I can't see an option with a regex or sed. I think you'll have to do clean by hand or craft something to parse line by line and replace if the \n is outside a string or function call (even that sounds tricky).

分享给朋友:
您可能感兴趣的文章:
随机阅读: