Using regular expressions in JavaScript to substitute an equal sign that is immediately followed by a line break

I need help creating a regex expression that will remove equal signs followed by a new line.

For instance, the text below shows each line ending with an equals sign and a new line character.

<p style=3D"border-bottom: 1px solid lightgrey; padding-bottom: 10px; margi=
n-bottom: 10px">From @mytwitterrrr filtered:<br></p><div><div><a href=3D"ht=
tps://feeder.co/p/076b2f56-af6c-11eb-adf3-1a21cf3a468a?u=3Da6566144-b0a5-4d=

I want to specifically target and replace equal signs occurring at end of each line without affecting other occurrences in the text.

let modified = message.replace(/\n*.+=/g,',') 

Any assistance with this would be greatly appreciated! Thank you.

Answer №1

This code snippet should solve the issue:

/=\n/g, ''

const inputString = `<p style=3D"border-bottom: 1px solid lightgrey; padding-bottom: 10px; margi=
n-bottom: 10px">From @sl_steamroom filtered:<br></p><div><div><a href=3D"ht=
tps://feeder.co/p/076b2f56-af6c-11eb-adf3-1a21cf3a468a?u=3Da6566144-b0a5-4d=
`
const outputString = inputString.replace(/=\n/g, '');

document.querySelector('#div').innerHTML = outputString
console.log(outputString)
<div id="div"></div>

Answer №2

The following script will substitute every occurrence of = that is immediately followed by a line break, without replacing the line break character itself.

let modified = text.replace(/=(?=\n)/g,',')

This is achieved by utilizing a look-ahead mechanism (?=\n) which scans for the newline character \n ahead.

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

The Angular Http Interceptor is failing to trigger a new request after refreshing the token

In my project, I implemented an HTTP interceptor that manages access token refreshing. If a user's access token expires and the request receives a 401 error, this function is designed to handle the situation by refreshing the token and re-executing ...

Verify that the text entered in the form is accurate, and if it meets the required criteria, proceed to the next

Is it possible to achieve this without using JavaScript? If not, I'd like to find the simplest solution. I have a form that functions similar to a password entry field, and I would like to redirect users to a certain page if they type in a specific p ...

Use Node.js with Selenium and WebdriverIO to simulate the ENTER keypress action on

I have put in a lot of effort trying to find the solution before resorting to asking this question, but unfortunately I have not been successful. All I need to know is how to send special characters (such as the enter key and backspace) with Node.js using ...

Encountering an issue with top-level await in Angular 17 when utilizing pdfjs-dist module

While using the Pdfjs library, I encountered an error message that reads: Top-level await is not available in the configured target environment ("chrome119.0", "edge119.0", "firefox115.0", "ios16.0", "safari16.0" + 7 overrides) /****/ webpack_exports = g ...

A guide to implementing drag and drop functionality using JavaScript

I have developed a unique drag and drop application that features both a left and right panel. The issue I am facing is that when I drag the ball from the left panel to the right panel, it does get dragged successfully. However, the problem arises when the ...

What could be causing this JavaScript code to run sluggishly in Internet Explorer despite its simple task of modifying a select list?

I am currently developing a multi-select list feature where users can select items and then rearrange them within the list by clicking either an "Up" or "Down" button. Below is a basic example I have created: <html> <head> <tit ...

When TableRow's onSelectChange is activated, it correctly selects the entire Table Group instead of an

In my React TypeScript application, I am working with an Array of Objects to populate a table. Each table row is grouped by category, and within each row, there is a select box that triggers an event to select all items with the same category: https://i.s ...

Dealing with CORS policy challenge

I am encountering an issue with Access to XMLHttpRequest at 'http://demo.equalinfotech.com/Iadiva/images/product/1634623781ladiva_barbara_01.glb' from origin 'http://localhost:8100' being blocked by CORS policy due to the absence of the ...

Implement a cron job in Node.js to automatically trigger an Express route on a weekly basis

I need to run tests on a certain page every week by creating a cron job that will access my express route at regular intervals. Currently, I have set up a cron job to run every 2 minutes as a test: //schedule job every 2 minutes schedule.scheduleJob("* /2 ...

Determine the availability of a distant website through AJAX requests

My website runs PHP's cURL to check the online status of 5 different URLs, however, this process tends to slow down the page load time significantly, especially if one of the sites being checked is not working. Someone suggested using jQuery's a ...

When I attempt to connect to my local MongoDB database, including a specific port in the URI is preventing the connection from being

While testing a connection to a local DB using mongoose and mongodb, I encountered an issue. Whenever I include a port number in the URI passed to mongoose.connect(), I receive a connection refused error. async function connectDB() { const db = await m ...

moodle - eliminate the need for grading at the same time

I'm currently setting up a Moodle installation and I'm looking for suggestions on how to prevent simultaneous grading. My goal is to have several evaluators grading students across various courses without any conflicts. If you have any recommend ...

Customizing ArrowDownwardIcon within MuiTableCell in Mui v5

I am attempting to modify the default color of the ArrowDownIcon within a TableCell using global theming in the following manner: MuiTableSortLabel: { styleOverrides: { root: { '&&.MuiTableSortLabel-icon': { ...

The PHP header() function is not properly redirecting the page, instead it is only displaying the HTML

After double checking that no client sided data was being sent beforehand and enabling error reporting, I am still encountering issues. The issue revolves around a basic login script with redirection upon validation. <?php include_once "database- ...

Trigger a new tab opening following an ajax response with Javascript

Having trouble opening in a new tab after receiving an ajax response with JavaScript, I attempted using both _newtab and _blank However, neither of them seem to be working. I wonder, Is there a solution available to find the answer? ...

How can we manage JSON data in chunks during a progress event?

My dilemma involves dealing with a server request that may bring back a substantial JSON list (around 100K records, approximately 50 Mb) of points to be presented on a canvas using D3js. To ensure interactivity and save memory, I am keen on rendering them ...

Troubleshooting Uploadify Issues

UPDATE: I discovered that the problem was related to Uploadify not having a session, which prevented it from accessing the designated page. To avoid this issue, simply direct it to a page without any admin login security ;) The issue stemmed from Upload ...

What is the best way to create operating system-neutral file paths in Node.js?

I'm currently fixing issues with my code while running integration tests on an EC2 instance of a Windows machine. Despite resolving the filenames-are-too-long problem, several paths remain unresolved due to being hardcoded for UNIX systems. I've ...

What is the process for running a continuous stream listener in a node.js function?

I am currently working with a file called stream.ts: require('envkey') import Twitter from 'twitter-lite'; const mainFn = async () => { const client = new Twitter({ consumer_key: process.env['TWITTER_CONSUMER_KEY'], ...

What is the purpose of using href="javascript:void()?

As I was pondering over this query: What exactly does "javascript:void(0)" signify?, I realized the rationale behind using <a href="javascript:void(0)" - to prevent any redirection of the page. Recently, I stumbled upon this snippet of code: <a id= ...