CMake: how to get the backslash literal in Regexp replace?

一世执手 提交于 2019-11-28 11:01:23

The reason is that in a CMake string literal, the backslash is an escape character (just like in C, Java or JavaScript) and in regex, the backslash is an escape character as well.

So to represent a regex as a string literal, you need double escaping. (That's why many "higher level" languages have regex literal notation, BTW.)

The string literal "\\" represents the in-memory string "\" and that's an invalid regex, hence the "ends in a backslash" error.

The string literal "\\\\" represents "\\" in memory which is a valid regex (representing a single backslash).

lgwest

This is a simpler way to do it

file(TO_NATIVE_PATH ${MYPATH} MYPATH)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!