【问题标题】:copy id="uniqueid" as name="uniqueid" with find/replace & regex in notepad++将 id="unique id" 复制为 name="unique id",并在 notepad++ 中使用查找/替换和正则表达式
【发布时间】:2020-09-21 16:21:21
【问题描述】:

我有一个 HTML 表单,目前每个输入(或选择)都有唯一的 ID,就像这样。

示例 1

<input type="number" id="qty-a-row" min="0" max="999" autocomplete="off" value="" style="border:0px; outline:0px; display:inline-block; width:50px;" />

示例 2

<select id="ps_a_row" autocomplete="off" style="width:324px; border:0px; outline:0px; display:inline-block">

每个 id 都是唯一的。我现在正在尝试添加一个与每个 id="" 相同的值的 name="" ,因此上面的示例 1 变为。

<input type="number" id="qty-a-row" name="qty-a-row" min="0" max="999" autocomplete="off" value="" style="border:0px; outline:0px; display:inline-block; width:50px;" />

示例 2 变为...

<select id="ps_a_row" name="ps_a_row" autocomplete="off" style="width:324px; border:0px; outline:0px; display:inline-block">

对于它找到的每个 id="anything" 以此类推。

我正在使用记事本++,并且正在尝试使用正则表达式打勾...

Find = id="(.*)"
Replace = id="\1" name="\1"

但这只是找到一些 id,并复制了它在找到的 id 之后找到的所有其他标签。

我正在尝试编辑的表单的完整代码在这里... https://pastebin.com/ZAE4Gffk

【问题讨论】:

  • 那些已经有name属性的标签呢?

标签: regex notepad++


【解决方案1】:

找到 id="([^"]+)" 并将其替换为 id="\1" name="\1" ,但您不应该使用正则表达式进行 HTML 操作。为此请使用适当的工具。

Demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-03
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2015-01-11
    • 2012-12-02
    相关资源
    最近更新 更多