当在搜索模式中使用newline时,dreamweaver regex替换失败。

时间:2022-03-28 22:58:08

I am trying to use

我在用

\nx

as the pattern and

模式和

\ny

as the replacement in Dreamweaver CS6. The file is located on a Win7 machine and is put to a CentOS6.4 server for use.

作为Dreamweaver CS6中的替换。该文件位于Win7机器上,并被放在CentOS6.4服务器上使用。

The idea is to replace an x at the start of a line with a y. Dreamweaver finds the pattern ok but no matter what I choose as a replacement, nothing is replaced.

我们的想法是在一行的开头用一个y来替换一个x。Dreamweaver发现这个模式没有问题,但是无论我选择什么作为替换,都不会被替换。

1 个解决方案

#1


3  

It turns out this file is using \r\n (carriage return and newline) for a line delimiter rather than only \n (newline) as was expected. The solution is to use

原来这个文件使用\r\n(回车和换行)作为行分隔符,而不是像预期的那样只使用\n(换行)。解决方法是使用。

(\r?\n)x

as the pattern and

模式和

$1y

as the replacement.

作为替代。

Works like a champ. The file source lives on a Win7 laptop but is put to a UNIX box (CentOS 6.4) for actual use.

就像一个冠军。该文件源代码位于Win7笔记本电脑上,但会被放到UNIX box (CentOS 6.4)中以供实际使用。

Also, a big thank you to commenter for suggestion to make \r conditional so pattern will handle both Linux / UNIX and Windows.

另外,非常感谢您对使\r有条件的建议,使pattern可以同时处理Linux / UNIX和Windows。

#1


3  

It turns out this file is using \r\n (carriage return and newline) for a line delimiter rather than only \n (newline) as was expected. The solution is to use

原来这个文件使用\r\n(回车和换行)作为行分隔符,而不是像预期的那样只使用\n(换行)。解决方法是使用。

(\r?\n)x

as the pattern and

模式和

$1y

as the replacement.

作为替代。

Works like a champ. The file source lives on a Win7 laptop but is put to a UNIX box (CentOS 6.4) for actual use.

就像一个冠军。该文件源代码位于Win7笔记本电脑上,但会被放到UNIX box (CentOS 6.4)中以供实际使用。

Also, a big thank you to commenter for suggestion to make \r conditional so pattern will handle both Linux / UNIX and Windows.

另外,非常感谢您对使\r有条件的建议,使pattern可以同时处理Linux / UNIX和Windows。