问题描述
<someElement name="Sometext">
<someElement name="Sometext" newattribute="Sometext_8c54">
在上面,我只想复制 name 属性并创建一个 newattribute ,其值为 name 属性,并带有 _4digitrandomhexadecimal
如何在记事本++中实现此目标
解决方法
如果使用 EmEditor ,请按 Ctrl + H 弹出 Replace 对话框,然后输入:
查找:<(.*?)name="(.*?)">
替换为:\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
表示它是JavaScript。 \1
和\2
是反向引用,指向匹配字符串中的第一个(.*?)
和第二个(.*?)
。 (Math.floor(Math.random()*16)).toString(16)
是随机的十六进制字符。
参考:http://www.emeditor.org/en/howto_search_replacement_expression_syntax.html