仅使用带有正则表达式支持的Notepad ++我想从txt文件中提取一些数据,表示地理坐标并组织输出:
-123456789
变为-123.456789
123456789
变为123.456789
-23456789
变为-23.456789
56789
变为0.056789
-89
变为-0.000089
试过这个:(-?)([0-9]*)([0-9]{6})
但是当输入长度小于6位时失败
答案 0 :(得分:0)
您可以通过三个步骤完成此操作:
(-?)\b(\d{1,6})\b
替换为\10000000\2
(-?)(\d{0,})(\d{6})
替换为\1\2.\3
0{2,}\.
替换为0.
这个想法很简单:
最后输出
-123.456789
123.456789
-23.456789
0.056789
-0.000089
检查以下三个步骤:
答案 1 :(得分:0)
你需要在notepad ++中使用2个步骤才能执行此操作。首先,我们来看看正则表达式:
(?<sign>-?)(?<first>\d+(?=\d{6}))?(?<last>\d+)
分组捕获必要的部分。
说明:(如果需要,可以丢失命名分组)
(?<sign>-?) # read the '-' sign
(?<first>\d+(?=\d{6}))? # read as many digits as possible,
# leaving 6 digits at the end.
(?<last>\d+) # read the remaining digits.
请参阅regex101.com
如何在记事本++中使用它?使用两步搜索并替换:
(-?)(\d+(?=\d{6}))?(\d+)
替换为:
\1(?2\2.:0.)000000\3 # copy sign, if group 2 contains any
# values, copy them, followed by '.'.
# If not show a '0.'
# Print 6 zero's, followed by group 3.
接下来,替换多余的零。
\.(0+(?=\d{6}\b))(\d{6}) # Replace the maximum number of zero's
# leaving 6 digits at the end.
替换为:
.\2
答案 2 :(得分:0)
您可以使用可用于记事本++的Python Script插件:
editor.rereplace('(\d+)', lambda m: ('%f' % (float(m.group(1))/1000000)))