Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9209289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:48:26+00:00 2026-06-18T00:48:26+00:00

I am working on a text editor and when the page renders I am

  • 0

I am working on a text editor and when the page renders I am trying to convert all <div> tag in to <p> tag if there is no style attribute in the tag using following javascript regex. (Soruce html at the end)

// if <div> has any attribute then do not convert in <p> tag
str = str.replace(/<div>([\w\W]*?)<\/div>/gi, '<p>$2</p>');

But the output of this regx is weird

OUTPUT HTML: Notice the unexpected '<p>$2</p>' at the end and Zoltan and congratulation text goes missing.

<br>
@abc Semantics
<br>
<a href="http://abc.com">http://abc.com</a>
<br>
xxxx5555
<br>
Mail address:
<a target="blank" href="/abc-abc-semantics">@abc</a>
<br>
<br>
<b>
Sub:
</b>
<br>
<br>
Hi abc,&nbsp;<p>$2</p><p>$2</p>;<p>$2</p><p>$2</p>

//Original HTML on which I am applying the regx

<br> 
  @abc Semantics 
<br> 
  <a href="http://abc.com">http://abc.com</a> 
<br> 
  xxxx5555 
<br> 
  Mail address: <a href="/abc-abc-semantics" target="blank">@abc</a> 
<br> 
<br> 
  <b> Sub: </b> 
<br> <br> 
Hi abc,&nbsp;
<div><br></div>

<div>congratulations :D</div>

<div><br></div>
;
<div>Zoltan</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:48:27+00:00Added an answer on June 18, 2026 at 12:48 am

    There is no group 2 in your regex, so $2 is taken as $2 only, and no replacement it done.

    You need to use $1: –

    str = str.replace(/<div>([\w\W]*?)<\/div>/gi, '<p>$1</p>');
    

    See demo on http://fiddle.re/v0jb

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a rich text editor. I do that using following jQuery.
I'm trying to make a simple text editor with winapi, its working for simple
I am using the YUI Rich Text Editor (YAHOO.widget.Editor), and I got it working
I'm working on a text editor in ruby, and I need to support a
I'm working on a rich text editor like web application, basically a XML editor
I am working on a cocoa-based text editor. Should I base it on NSTextView
I'm working on my own text editor in silverlight. I made different functions to
I've got a really annoying problem: I'm working on a collaborative text editor in
Currently I'm working on Text to speech in android and I'm trying to build
I'm working on an editor page for a project in ASP.NET MVC. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.