Remove very specific whitespace combination from string Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Remove very specific whitespace combination from string without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have an input string that I need to remove a very specific combination of whitespace characters from and I cannot figure out how to create a regex that will remove only this specific combination of characters. I have lost track of the different regex combination I have tried off and on over the past few weeks.

The format of the string I’m trying to remove is “{space}{space}{newline}{newline}{space}{space}{newline}”. It can be seen in the HTML snippet below.

<div class="row">
+ Process products in strict compliance with cGMP and SOPs.
  

  
+ Operate and maintain production equipment.
  

  
+ Participate in all production activities, including manufacturing, packaging, punching, and pouching of products.
  

  
+ Clean equipment and manufacturing room in compliance with established policies and regulatory requirements.
</div>

The expected output should be this:

<div class="row">
+ Process products in strict compliance with cGMP and SOPs.
  

  
+ Operate and maintain production equipment.
  

  
+ Participate in all production activities, including manufacturing, packaging, punching, and pouching of products.
  

  
+ Clean equipment and manufacturing room in compliance with established policies and regulatory requirements.
</div>

Hopefully someone can help me.

Answer

Something like this?

const div = document.querySelector(".row")
let text = div.textContent;
div.innerHTML = text.replace(/(s+)?n(s+)?/g,"<br>")
.row { whitespace: pre }
<div class="row">
+ Process products in strict compliance with cGMP and SOPs.
  

  
+ Operate and maintain production equipment.
  

  
+ Participate in all production activities, including manufacturing, packaging, punching, and pouching of products.
  

  
+ Clean equipment and manufacturing room in compliance with established policies and regulatory requirements.
</div>
We are here to answer your question about Remove very specific whitespace combination from string - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji