如何使用R将字符串转换为所需的格式?

时间:2018-02-16 09:45:05

标签: r regex

我跟下面的字符串:

KVNProgress Group/Users/xxx/Documents/project/Pods/KVNProgress/KVNProgress/Resources/KVNProgressView.xib
/Users/xxx/development/project/Pods/KVNProgress/KVNProgress/Resources/KVNProgressView.xib: Internal error. Please file a bug at bugreport.apple.com and attach "/var/folders/kb/3qmqmk_569v9ggc23nnc5btm0000gn/T/IB-agent-diagnostics_2018-02-16_10-30-34_345000".

使用R使用正则表达式,我需要将上面的字符串转换为以下格式:

Process:               Interface Builder Cocoa Touch Tool [10066]
Path:                  /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Overlays/Interface Builder Cocoa Touch Tool
Identifier:            Interface Builder Cocoa Touch Tool
Version:               9.2 (13772)
Code Type:             X86-64 (Native)
Parent Process:        ibtoold [10050]
Responsible:           Interface Builder Cocoa Touch Tool [10066]
User ID:               262
Date/Time:             2018-02-15 14:33:28.445 +0100
OS Version:            Mac OS X 10.12.6 (16G1114)
Report Version:        12
Anonymous UUID:        C68970F4-1365-1C3A-554B-396EA6A954FC
Time Awake Since Boot: 1800 seconds
System Integrity Protection: enabled
Crashed Thread:        0
Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY
Termination Reason:    DYLD, [0x1] Library missing
Application Specific Information:
dyld: launch, loading dependent libraries DYLD_FALLBACK_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks DYLD_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Xcode/Overlays:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks
Library not loaded: /System/Library/PrivateFrameworks/CoreAnalytics.framework/CoreAnalytics
Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/WirelessDiagnostics.framework/WirelessDiagnostics
Reason: image not found

1 个答案:

答案 0 :(得分:1)

喜欢这个吗?

text <- c("Names:Cummins, Inc. Cummins Engine Company, Inc.| Variant title:Dodge Ram 24 valve turbo diesel, 2000.0 model year wiring diagram :bull. no. 3666481.|")
gsub("(\\b[A-Z][\\w\\s]+:)[^|]+", "\\1", text, perl = TRUE)

这会产生

[1] "Names:| Variant title:|"

请参阅a demo on regex101.com