在下面的文字中:
document1=DFMS
doc1.fields=VERTICAL|OUTWARD NUMBER|SUBJECT|ADDRESS|LANGUAGE|ANNEXURE|REMARKS|DATE OF CREATION|CREATOR-EMPLOYEE CODE
doc1.field1=ITV
doc1.field2=2017NOV11/L00105833
doc1.field3=confirmation to your BG No.0031BGR0058417 dated novemebr 3, 2016
doc1.field4=NIL
doc1.field5=B
doc1.field6=1
doc1.field7=DFMS - BULK UPLOAD
doc1.field8=11-11-2016
doc1.field9=050080
doc1.location=RAPID/INFORMATION TECHNOLOGY VERTICAL – ITV/OPERATIONAL/DFMS Data
doc1.create_location=True
doc1.append=False
doc1.delete_images=False
在第11行中,doc1.field8=11-11-2016
需要-
将 改为 ,/
使其成为
doc1.field8=11/11/2016
。
挑战在于,带有日期值(dd-mm-yyyy)的行在文本文件中出现多次,需要将其更改为(dd/mm/yyyy)才能进一步处理。
答案1
- Ctrl+H
- 找什么:
=(\d\d)-(\d\d)-(\d{4})$
- 用。。。来代替:
=$1/$2/$3
- 查看 环绕
- 查看 正则表达式
- Replace all
解释:
= # equal sign
(\d\d) # group 1, 2 digits (the day/month)
- # hyphen
(\d\d) # group 2, 2 digits (the month/day)
- # hyphen
(\d{4}) # group 3, 4 digits (the year)
$ # end of line
替代品:
= # equal sign
$1 # content of group 1 (the day/month)
/ # a slash
$2 # content of group 2 (the month/day)
/ # a slash
$3 # content of group 3 (the year)
截图(之前):
截图(之后):