[英]Find and replace in Notepad++ with specific text
I have xml file where i need to do some changes for an element.我有一个 xml 文件,我需要在其中对元素进行一些更改。
<someElement name="Sometext">
I want to modify the above with an attribute like this我想用这样的属性修改上面的内容
<someElement name="Sometext" newattribute="Sometext_8c54">
In the above i just want to copy the name attribute and create a newattribute which has the value of name attribute with _4digitrandomhexadecimal在上面我只想复制name属性并创建一个newattribute ,它的name属性值为_4digitrandom 十六进制
How can I achieve this in notepad++我怎样才能在记事本++中实现这一点
If you use EmEditor , press Ctrl + H to bring up the Replace dialog box, and enter:如果您使用EmEditor ,请按Ctrl + H 调出替换对话框,然后输入:
Find : <(.*?)name="(.*?)">
查找: <(.*?)name="(.*?)">
Replace with : \\J "<\\1name=\\"\\2\\" newattribute=\\"\\2_" + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + "\\">"
替换为: \\J "<\\1name=\\"\\2\\" newattribute=\\"\\2_" + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + (Math.floor(Math.random()*16)).toString(16) + "\\">"
set the Regular Expressions option, and click Replace All .设置正则表达式选项,然后单击全部替换。
Explanation解释
\\J
in the beginning of the Replace with string means that it is a JavaScript.以字符串开头的\\J
表示它是一个 JavaScript。 \\1
and \\2
are back references referring to the first (.*?)
and second (.*?)
in the matched string. \\1
和\\2
是引用匹配字符串中的第一个(.*?)
和第二个(.*?)
反向引用。 (Math.floor(Math.random()*16)).toString(16)
is a random hexadecimal character. (Math.floor(Math.random()*16)).toString(16)
是一个随机的十六进制字符。
References: http://www.emeditor.org/en/howto_search_replacement_expression_syntax.html参考资料: http : //www.emeditor.org/en/howto_search_replacement_expression_syntax.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.