增量替换数字数字模式?
假设我想要 10 行数据,但我想要为每行或每条数据递增一个值。我如何增加该值?
例如...如果我有这些行,是否有正则表达式方法可以替换 id 值以递增?
<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />
--- 这是我希望它看起来像的样子...(如果第一行的 id 上升,那就可以了)
<row id="1" />
<row id="2" />
<row id="3" />
<row id="4" />
<row id="5" />
Lets say I want to have a 10 rows of data but I want a value to increment for each row or piece of data. How do I increment that value?
For example....If I have these rows, is there a regex way of replacing the id values to increment?
<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />
<row id="1" />
--- Here is what I would like it to look like... (if the first row's id goes up one thats ok)
<row id="1" />
<row id="2" />
<row id="3" />
<row id="4" />
<row id="5" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不确定正则表达式,但有一种方法可以在 Notepad++ 中执行此操作,尽管它不是很灵活。
在您提供的示例中,按住
Alt
并选择您要更改的数字列。然后转到编辑->列编辑器
,并在出现的窗口中选择要插入的数字
单选按钮。然后指定您的初始数字和增量,然后单击“确定”。它应该写出递增的数字。注意:这也适用于
多重编辑
功能(在按住Ctrl键的同时选择多个位置)。但是,这并不是在任何地方接近大多数人认为有用的灵活性。 Notepad++ 很棒,但如果你想要一个真正强大的编辑器,可以轻松完成这样的事情,我会建议使用 Vim。
Not sure about regex, but there is a way for you to do this in Notepad++, although it isn't very flexible.
In the example that you gave, hold
Alt
and select the column of numbers that you wish to change. Then go toEdit->Column Editor
and select theNumber to Insert
radio button in the window that appears. Then specify your initial number and increment, and hit OK. It should write out the incremented numbers.Note: this also works with the
Multi-editing
feature (selecting several locations while maintaining Ctrl key pressed).This is, however, not anywhere near the flexibility that most people would find useful. Notepad++ is great, but if you want a truly powerful editor that can do things like this with ease, I'd say use Vim.
我今天正在寻找相同的功能,但无法在 Notepad++ 中执行此操作。不过,我们有 TextPad 来救援。这对我有用。
在 TextPad 的替换对话框中,打开正则表达式;那么您可以尝试替换
为
查看此链接以了解 TextPad 的更多令人惊叹的替换功能 -
http://sublimetext.userecho.com/topic/106519-generate -数字序列增量替换/
I was looking for the same feature today but couldn't do this in Notepad++. However, we have TextPad to our rescue. It worked for me.
In TextPad's replace dialog, turn on regex; then you could try replacing
by
Have a look at this link for further amazing replace features of TextPad -
http://sublimetext.userecho.com/topic/106519-generate-a-sequence-of-numbers-increment-replace/
我在超过 250 行时遇到了同样的问题,这就是我的做法:
例如:
将光标放在“1”之后,然后单击
alt + shift
并开始按 down 降序箭头直到到达底线,现在您看到一组选择,单击擦除以同时擦除每行上的数字 1,然后转到Edit ->列编辑器
并选择要插入的数字
,然后将1
放入初始数字字段中,将1
放入增量字段中,并检查零数字和点击ok
恭喜你做到了:)
i had the same problem with more than 250 lines and here is how i did it:
for example :
you put the cursor just after the "1" and you click on
alt + shift
and start descending with down arrow until your reach the bottom line now you see a group of selections click on erase to erase the number 1 on each line simultaneously and go toEdit -> Column Editor
and selectNumber to Insert
then put1
in initial number field and1
in incremented by field and check zero numbers and clickok
Congratulations you did it :)
由于真正的答案有限,我将分享这个解决方法。对于像您的示例这样真正简单的情况,您可以向后执行...
从此
将
\r\n
替换为" />\r\n
或者是类似的方式,你可以使用 excel/电子表格来破解数据。只需将原始数据拆分为列并根据需要操作值即可。
这是显而易见的事情,但它可能会帮助某人做一些奇怪的一次性黑客工作,以节省一些击键次数。
Since there are limited real answers I'll share this workaround. For really simple cases like your example you do it backwards...
From this
Replace
\r\n
with" />\r\n<row id="
and you'll get 90% of the way thereOr is a similar fashion you can hack about data with excel/spreadsheet. Just split your original data into columns and manipulate values as you require.
Obvious stuff but it may help someone doing the odd one-off hack job to save a few key strokes.
http://docs.notepad-plus-plus.org/index.php/Inserting_Variable_Text
Notepad++ 自带一个编辑-> “Alt+C”列编辑器可以通过两种不同的方式处理矩形选区:Coledit.png
在插入点(也称为插入符号)的列处(包括当前行及其之后的每一行)插入一些固定文本。最初选择的文本保持不变。
如图所示,可以以相同的方式插入一系列线性数字。应提供起始值和增量。可以选择用零向左填充,并且可以以 2、8、10 或 16 为基数输入数字 - 这也是计算值的显示方式,填充基于最大值。
http://docs.notepad-plus-plus.org/index.php/Inserting_Variable_Text
Notepad++ comes equipped with a Edit -> Column "Alt+C" Editor which can work on a rectangular selection in two different ways: Coledit.png
inserting some fixed text on every line including and following the current line, at the column of the insertion point (aka caret). Initially selected text is left untouched.
As the picture illustrates, a linear series of numbers can be inserted in the same manner. The starting value and increment are to be provided. Left padding with zeroes is an option, and the number may be entered in base 2, 8, 10 or 16 - this is how the computed values will be displayed too, padding being based on the largest.