Using regex to replace problems with line breaks with BR tags

I have a block of text that I need to modify by replacing BR tags with \n in order to create new lines.

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>

I've tried the following script, but it doesn't seem to be replacing the content as expected. Can you help me identify what I'm doing wrong?

this.downloadData.forEach(x => x.ServiceLogStatus = x.ServiceLogStatus.replace(/<br\s*\/?>/mg, '\n')); 

Take a look at the data below:

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: ""

Answer №1

Your code looks solid for implementing the regex replacement. It effectively substitutes all occurrences of `<br>` with new lines:

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'));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best method for deleting a portion of a string following the final instance of a particular character?

I have a single string that looks like this: "Opportunity >> Source = Email >> Status = New >> Branch = Mumbai" My goal is to truncate the string from the last occurrence of >>. Essentially, I want the resulting string to be: "Op ...

Angular 2 Validation Customizer

Recently, I created a web API function that takes a username input from a text field and checks if it is already taken. The server response returns Y if the username is available and N if it's not. For validating the username, I implemented a Validat ...

A dynamic image carousel featuring multiple images can be enhanced with fluid movement upon a flick of

I am trying to enhance this image slider in HTML and CSS to achieve the following objectives: 1. Eliminate the scroll bar 2. Implement swipe functionality with mouse flick (should work on mobile devices as well) 3. Make the images clickable .slider{ ove ...

Executing a search within the current connection in Node.js

In the code snippet provided, the need is to execute the second SQL query (query2) after constructing it based on the results of the first query (query1). However, even though the second query is successfully built, it is not being executed. Assistance i ...

JavaScript has encountered an Uncaught TypeError due to an illegal invocation

I am currently developing a lambda function that calls another function with specific parameters. While this code runs without issues in Firefox, it encounters an error in Chrome, displaying a strange message in the inspector: Uncaught TypeError: Illegal ...

Activate dynamic form fields using Ajax

Consider a scenario where the code looks like this: <div id="stuff<? echo $dynID; ?>" class="bla"> <form id="myform<? echo $dynID; ?> " action="bla.php"> <input name="iname<? echo $dynID; ?>" value="<? echo $row[1] ...

What is the process of retrieving the return value after creating data in Firestore

I have been experimenting with creating data using firestore in the following manner: createData({state}) { return db.collection('items').add({ title: state.title, ingredients: state.ingredients, creat ...

Utilizing Props to Manage State within Child Components

Is it possible to assign the props received from a Parent Component as the state of a Component? export default class SomeComp extends Component { constructor(props) { super(props); this.state = someProps; // <-- I want to set the ...

When the checkbox is unchecked, any appended HTML should be removed

Is there a way to modify JS code in order to delete text content from ul.results after unchecking a checkbox? It seems that if the text consists of only simple letters or numbers, it gets removed when the checkbox is unchecked. However, if the text contain ...

What are effective ways to eliminate script tags from a webpage?

I have implemented tags on my website that users can use to interact with the site. My goal is to figure out how to make the browser only read text from a specific file I write, without any HTML. This should be restricted to certain sections of my websit ...

How to keep text always locked to the front layer in fabric.js without constantly bringing it to the front

Is it possible to achieve this functionality without using the following methods? canvas.sendBackwards(myObject) canvas.sendToBack(myObject) I am looking to upload multiple images while allowing them to be arranged forward and backward relative to each o ...

I am looking for a way to convert the date format from "yyyy-MM-dd" to "dd-MM-yyyy" in NestJs

I need help with changing the date format from "yyyy-MM-dd" to "dd-MM-yyyy". Currently, my entity code looks like this: @IsOptional() @ApiProperty({ example: '1999-12-12', nullable: true }) @Column({ type: 'date', nullable: true } ...

Is there a way to display points on each vertex of my geometry using React, three.js, and Three-React-fiber?

I'm trying to figure out how to utilize the pointsmaterial and points object within three-react-fiber. Currently, I have a custom geometry that I've imported from a .gltf file and I'm rendering it like this: <mesh castShadow recei ...

Error NS_ERROR_XPC_BAD_CONVERT_JS occurred while attempting to execute an AJAX function

As I try to close the Thickbox in my Wordpress site after selecting an image, I encounter an issue that involves adding the selected image to the screen successfully, followed by running a small AJAX routine to update a database option, which triggers an e ...

Struggling to configure webpack to set NODE_ENV to production mode

Trying to utilize webpack 2.2.1 for constructing a react-redux application aimed at production, but encountering difficulties setting process.env.NODE_ENV to production. Take a look at my webpack.config.js: var webpack = require('webpack'); var ...

Errors in JavaScript are displayed when a React application is built for production

I have developed a client react application using create-react-app. It communicates with a node server that runs an express api. During development, everything was smooth sailing and I was preparing for deployment. After running npm run build, there were ...

Embedding a table inside a Bootstrap popover

I'm struggling with adding a table inside a Bootstrap popover. When I click on it, the table doesn't show up. This is my first time trying to insert HTML into a popover, so I don't know the correct way to do it. Any help would be appreciated ...

pass the table ID to the controller using AngularJS

Curious about how to pass the selected row's id from a table to the controller when displaying its details? Take a look at this code snippet: app.js: .controller("etudmodifCtrl", ["$scope", "$http", "filterFilter", "$rootScope", "logger", "$filter", ...

grunt-webpack claims to have completed without any errors, yet it has failed to bundle any files

Over the past week, I've been attempting to get grunt, babel, and webpack to work together smoothly. Despite trying various solutions that I found during my research, nothing seems to be working as intended. Below is the relevant portion of my gruntfi ...

React Router - Implementing a <Redirect> element rather than a list of child components

Here is the code snippet I am working with: import { Redirect } from 'react-router-dom'; import QPContent from '../QPContent'; class AnswerContainer extends Component { constructor(props) { super(props); this.state = { ...