这是列表的一部分。所有行都需要在每行的开头填充最多12个字符的零。有些行已经是12 ...
801095126710
2227121
19472168
21521070
21945110
25260089
92000077
93400015
132300300
132405100
211304212
934000107
934000108
934000110
934000120
934000144
93400138
160908013840
822100052908
822100053358
如何使用正则表达式完成?
答案 0 :(得分:3)
警告这很难看。
您可以寻找:
^(.{0,11})$
并替换为0$1
。点击替换所有 11次和voilà。
你不能用正则表达式做数学运算。正则表达式用于字符串匹配。
答案 1 :(得分:1)
I see this as a two step process. Step One insert 12 0
at the beginning of each line. Step Two capture the last 12 characters and all leading 0
, and replace with just the 12 captured characters.
^
Replace with: 000000000000
Live Demo: https://regex101.com/r/rM8bK2/1
上触发touchstart事件时阻止滚动但不会链接关注示例文字
801095126710
2227121
19472168
21521070
21945110
25260089
92000077
93400015
132300300
132405100
211304212
934000107
934000108
934000110
934000120
934000144
93400138
160908013840
822100052908
822100053358
替换后
000000000000801095126710
0000000000002227121
00000000000019472168
00000000000021521070
00000000000021945110
00000000000025260089
00000000000092000077
00000000000093400015
000000000000132300300
000000000000132405100
000000000000211304212
000000000000934000107
000000000000934000108
000000000000934000110
000000000000934000120
000000000000934000144
00000000000093400138
000000000000160908013840
000000000000822100052908
000000000000822100053358
123456789,123456789,123456789
注意:我在这里插入数字行以帮助说明字符的数量和位置
0*([0-9]{12})$
替换为: $1
现场演示: https://regex101.com/r/aS2xG0/1
示例文字
因为这是第二步,所以示例文本是上面第一步的输出
000000000000801095126710
0000000000002227121
00000000000019472168
00000000000021521070
00000000000021945110
00000000000025260089
00000000000092000077
00000000000093400015
000000000000132300300
000000000000132405100
000000000000211304212
000000000000934000107
000000000000934000108
000000000000934000110
000000000000934000120
000000000000934000144
00000000000093400138
000000000000160908013840
000000000000822100052908
000000000000822100053358
替换后
801095126710
000002227121
000019472168
000021521070
000021945110
000025260089
000092000077
000093400015
000132300300
000132405100
000211304212
000934000107
000934000108
000934000110
000934000120
000934000144
000093400138
160908013840
822100052908
822100053358
123456789,123456789,
注意:我在这里插入数字行以帮助说明字符的数量和位置