简体   繁体   English

记事本中的正则表达式可以替换

[英]Regex in Notepad++ to replace

I have the follow text in a document (using Notepad++). 我在文档中有以下文本(使用Notepad ++)。

Now, I want to replace all regex occurence with a ?. 现在,我想用?替换所有正则表达式。

I have: 我有:

'{$data}', '{$data2}', '{$res}','{$blahblahblah}'

And I want them to become ?,?,?,? 我希望他们成为?,?,?,?

I tried using \\b^'{(.+)}'$\\b but that doesn't seem to find the pattern. 我尝试使用\\b^'{(.+)}'$\\b但这似乎找不到模式。

You can use the following: 您可以使用以下内容:

'{\$[^}]+}'

And replace with ? 并替换为?

See DEMO 演示

Explanation: 说明:

  • '{\\$ match quote, curly brace and $ literls '{\\$匹配报价,大括号和$ liters
  • [^}]+} negated character class to match anything other than } more than once ( + ) followed by } ... Equivalent to .*?} but 2-3 times faster [^}]+}否定字符类,以匹配除}以外的任何其他字符( + ),然后匹配} ...等效于.*?}但要快2-3倍

You need to remove the anchors and word boundaries. 您需要删除锚点和单词边界。 And it would be perfect if you escape the braces. 如果您逃脱括号,那将是完美的。

'\{\$.*?\}'

Then replace the match with a ? 然后将匹配项替换为? symbol. 符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM