Xcode – Xcode replace 使用正则表达式替换文字

ChatGPT 3.5 国内中文镜像站免费使用啦

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 基础

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> Object-C 线程

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> OpenGL ES

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> GPUImage

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> AVFoundation

零基础 Object-C 学习路线推荐 : Object-C 学习目录 >> CocoaPods


一.需求

如果有这样一段代码:

2021-08-07 10:17:20.887209+0800 LearnAVFoundation[1535:63699] family:'Academy Engraved LET'
2021-08-07 10:17:20.887322+0800 LearnAVFoundation[1535:63699]     font:'AcademyEngravedLetPlain'
2021-08-07 10:17:20.887363+0800 LearnAVFoundation[1535:63699] -------------
2021-08-07 10:17:20.887391+0800 LearnAVFoundation[1535:63699] family:'Al Nile'
2021-08-07 10:17:20.887475+0800 LearnAVFoundation[1535:63699]     font:'AlNile'
2021-08-07 10:17:20.887506+0800 LearnAVFoundation[1535:63699]     font:'AlNile-Bold'
2021-08-07 10:17:20.887537+0800 LearnAVFoundation[1535:63699] -------------
2021-08-07 10:17:20.887566+0800 LearnAVFoundation[1535:63699] family:'American Typewriter'
2021-08-07 10:17:20.887656+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter'
2021-08-07 10:17:20.887683+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter-Light'
2021-08-07 10:17:20.887708+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter-Semibold'
2021-08-07 10:17:20.887730+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter-Bold'
2021-08-07 10:17:20.887755+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter-Condensed'
2021-08-07 10:17:20.887777+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter-CondensedLight'
2021-08-07 10:17:20.887806+0800 LearnAVFoundation[1535:63699]     font:'AmericanTypewriter-CondensedBold'
2021-08-07 10:17:20.887836+0800 LearnAVFoundation[1535:63699] -------------
2021-08-07 10:17:20.896586+0800 LearnAVFoundation[1535:63699] family:'Apple Color Emoji'
2021-08-07 10:17:20.896659+0800 LearnAVFoundation[1535:63699]     font:'AppleColorEmoji'
2021-08-07 10:17:20.896700+0800 LearnAVFoundation[1535:63699] -------------
2021-08-07 10:17:20.896745+0800 LearnAVFoundation[1535:63699] family:'Apple SD Gothic Neo'
2021-08-07 10:17:20.896866+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-Regular'
2021-08-07 10:17:20.896899+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-Thin'
2021-08-07 10:17:20.896930+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-UltraLight'
2021-08-07 10:17:20.896957+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-Light'
2021-08-07 10:17:20.896983+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-Medium'
2021-08-07 10:17:20.897014+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-SemiBold'
2021-08-07 10:17:20.897041+0800 LearnAVFoundation[1535:63699]     font:'AppleSDGothicNeo-Bold'
2021-08-07 10:17:20.897110+0800 LearnAVFoundation[1535:63699] -------------

最终结果:

 family:'Academy Engraved LET'
     font:'AcademyEngravedLetPlain'
 -------------
 family:'Al Nile'
     font:'AlNile'
     font:'AlNile-Bold'
 -------------
 family:'American Typewriter'
     font:'AmericanTypewriter'
     font:'AmericanTypewriter-Light'
     font:'AmericanTypewriter-Semibold'
     font:'AmericanTypewriter-Bold'
     font:'AmericanTypewriter-Condensed'
     font:'AmericanTypewriter-CondensedLight'
     font:'AmericanTypewriter-CondensedBold'
 -------------
 family:'Apple Color Emoji'
     font:'AppleColorEmoji'
 -------------
 family:'Apple SD Gothic Neo'
     font:'AppleSDGothicNeo-Regular'
     font:'AppleSDGothicNeo-Thin'
     font:'AppleSDGothicNeo-UltraLight'
     font:'AppleSDGothicNeo-Light'
     font:'AppleSDGothicNeo-Medium'
     font:'AppleSDGothicNeo-SemiBold'
     font:'AppleSDGothicNeo-Bold'
 -------------
 

当然内容不多,你可以直接手动替换,如果该文件有数万行呢??


二.Xcode replace 常规查找

图片[1]-Xcode – Xcode replace 使用正则表达式替换文字-猿说编程

该方法虽然可以删除一部分内容,但是很明显达不到要求!!得到结果:

2021-08-07 10:17:20.887209+0800  family:'Academy Engraved LET'
2021-08-07 10:17:20.887322+0800      font:'AcademyEngravedLetPlain'
2021-08-07 10:17:20.887363+0800  -------------
2021-08-07 10:17:20.887391+0800  family:'Al Nile'
2021-08-07 10:17:20.887475+0800      font:'AlNile'
2021-08-07 10:17:20.887506+0800      font:'AlNile-Bold'
2021-08-07 10:17:20.887537+0800  -------------
2021-08-07 10:17:20.887566+0800  family:'American Typewriter'
2021-08-07 10:17:20.887656+0800      font:'AmericanTypewriter'
2021-08-07 10:17:20.887683+0800      font:'AmericanTypewriter-Light'
2021-08-07 10:17:20.887708+0800      font:'AmericanTypewriter-Semibold'
2021-08-07 10:17:20.887730+0800      font:'AmericanTypewriter-Bold'
2021-08-07 10:17:20.887755+0800      font:'AmericanTypewriter-Condensed'
2021-08-07 10:17:20.887777+0800      font:'AmericanTypewriter-CondensedLight'
2021-08-07 10:17:20.887806+0800      font:'AmericanTypewriter-CondensedBold'
2021-08-07 10:17:20.887836+0800  -------------
2021-08-07 10:17:20.896586+0800  family:'Apple Color Emoji'
2021-08-07 10:17:20.896659+0800      font:'AppleColorEmoji'
2021-08-07 10:17:20.896700+0800  -------------
2021-08-07 10:17:20.896745+0800  family:'Apple SD Gothic Neo'
2021-08-07 10:17:20.896866+0800      font:'AppleSDGothicNeo-Regular'
2021-08-07 10:17:20.896899+0800      font:'AppleSDGothicNeo-Thin'
2021-08-07 10:17:20.896930+0800      font:'AppleSDGothicNeo-UltraLight'
2021-08-07 10:17:20.896957+0800      font:'AppleSDGothicNeo-Light'
2021-08-07 10:17:20.896983+0800      font:'AppleSDGothicNeo-Medium'
2021-08-07 10:17:20.897014+0800      font:'AppleSDGothicNeo-SemiBold'
2021-08-07 10:17:20.897041+0800      font:'AppleSDGothicNeo-Bold'

三.Xcode replace 正则表达式查找

基于第二步的结果执行:

2021-08-07(.*)0800

.* 表示直接匹配所有的字符,所以需要设置结束位置 Ends With ,而并非 Contains;

图片[2]-Xcode – Xcode replace 使用正则表达式替换文字-猿说编程

即可得到上面的完美结果~~


四.猜你喜欢


ChatGPT 3.5 国内中文镜像站免费使用啦
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容