我有以下文本,我需要用\ n替换BR标签,以便获得新的一行。
D:\HP\ConfigurationServer_3464\log\nvdmr***.log ~ File not
found<br>D:\HP\DCSSchedulerAgent_3478\logs\HTTPD-DCSSchedulerAgent-3478.log ~
File not found<br>D:\HP\MonitorClient\logs\windowsService.log ~ File not
found<br>D:\HP\PolicyServer_3467\logs\httpd-policyserver-3467.log ~ File not
found<br>D:\HP\ProxyServer_3466\logs\httpd-proxyserver-3466.log ~ File not
found<br>D:\HP\MessagingServer_3461\logs\rms.log ~ file not found<br>
这是我写的脚本,但从未被替换。我在做什么错
this.downloadData.forEach(x => x.ServiceLogStatus = x.ServiceLogStatus.replace(/<br\s*\/?>/mg, '\n'));
请查看数据:
CPUStatus: "1"
Connectivity: "Success"
DiskStatus: "Free Space C: 64.86%↵D: 68.6%↵E: 0%↵F: 0.01%↵G: 56.83%↵H: 80.78%↵I: 80.28%"
HostName: "gtdctiholdb01u"
LastRebootStatus: null
LogTime: "5/15/2019 11:26:01 AM"
MemoryStatus: "Memory Used: 89.86%"
RDPStatus: "05/11/2019 16:50:13"
ServiceLogStatus: " D:\HP\ConfigurationServer_3464\log\nvdmr***.log ~ File not found<br>D:\HP\DCSSchedulerAgent_3478\logs\HTTPD-DCSSchedulerAgent-3478.log ~ File not found<br>D:\HP\MonitorClient\logs\windowsService.log ~ File not found<br>D:\HP\PolicyServer_3467\logs\httpd-policyserver-3467.log ~ File not found<br>D:\HP\ProxyServer_3466\logs\httpd-proxyserver-3466.log ~ File not found<br>D:\HP\MessagingServer_3461\logs\rms.log ~ file not found<br>"
ServiceStatus: ""
SupportDL: ""
答案 0 :(得分:0)
您的replace regex实现似乎工作良好。它将所有<br>
换行:
const str = `D:\HP\ConfigurationServer_3464\log\nvdmr***.log ~ File not
found<br>D:\HP\DCSSchedulerAgent_3478\logs\HTTPD-DCSSchedulerAgent-3478.log ~
File not found<br>D:\HP\MonitorClient\logs\windowsService.log ~ File not
found<br>D:\HP\PolicyServer_3467\logs\httpd-policyserver-3467.log ~ File not
found<br>D:\HP\ProxyServer_3466\logs\httpd-proxyserver-3466.log ~ File not
found<br>D:\HP\MessagingServer_3461\logs\rms.log ~ file not found<br>`;
console.log(str.replace(/<br\s*\/?>/mg, '\n'));