开发者

Find replace with Regex adding extra text

开发者 https://www.devze.com 2023-01-21 03:15 出处:网络
I am using a regex within Visual Studio 2005 to turn my SQL statement into a readable string. I am using the find expression {.*} and the replace expression & \"\\1 \" _.

I am using a regex within Visual Studio 2005 to turn my SQL statement into a readable string.

I am using the find expression {.*} and the replace expression & "\1 " _.

This should produce results something like: input:

select *
from x

expected

& "select * " _
& "from x " _

The reality is I a开发者_JAVA技巧m getting:

& "select * " _& " "_
& "from x " _& " "_

Have I got my expression wrong?


For your find pattern, use a + instead of a * to ensure at least one character is matched. I think something extra is being picked up with the * approach, perhaps a boundary or line-break despite the documentation.

Try this pattern instead: {.+}

0

精彩评论

暂无评论...
验证码 换一张
取 消