我有一个CSV文件(从iWork Numbers导出的数据),其中包含一个包含信息的用户列表。我想要做的是在所有行上用;;;;;;;;;
替换;
接受“上次登录”。
通过这样做并再次将文件导入Numbers,数据将(希望)按行划分为:
User 1 | Points: 1 | Registered: 2012-01-01 | Last login 2012-02-02
User 2 | Points: 2 | Registered: 2012-01-01 | Last login 2012-02-02
CSV文件的外观:
;User1;;;;;;;;;
;Points: 1;;;;;;;;;
;Registered: 2012-01-01;;;;;;;;;
;Last login: 2012-02-02;;;;;;;;;
;User2;;;;;;;;;
;Points: 2;;;;;;;;;
;Registered: 2012-01-01;;;;;;;;;
;Last login: 2012-02-02;;;;;;;;;
所以我的问题是我应该在查找和替换字段中键入什么正则表达式代码?
提前致谢!
答案 0 :(得分:2)
请参阅正则表达式 in action :
Find : ^(;(?!Last).*)(;{9})
Replace: $1;
输出将是:
;User1;
;Points: 1;
;Registered: 2012-01-01;
;Last login: 2012-02-02;;;;;;;;;
;User2;
;Points: 2;
;Registered: 2012-01-01;
;Last login: 2012-02-02;;;;;;;;;
^ # Match start of the line
( # Start of the 1st capture group
;(?!Last) # Match a semicolon (;), only if not followed by 'Last' word.
.* # Match everything
) # End of the 1st capture group
( # Start of the 2nd capture group
;{9} # Match exactly 9 semicolons
) # End of the 2nd capture group
$1; # Leave 1st capture group as is and append a semicolon.