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 1053871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:19:09+00:00 2026-05-16T17:19:09+00:00

how to split <p><span>Hello</span></p> to <span>Hello</span> using javascript var text = <p><span>Hello</span></p>; remember:I don’t

  • 0

how to split <p><span>Hello</span></p> to <span>Hello</span> using javascript

var text = "<p><span>Hello</span></p>";

remember:I don’t know what contain <p>, I don’t know if <p> has any attribute or not

I found the answer !

var patt=/^<p.*?>(.*)<\/p>$/i;
var result=patt.exec(text);
alert(result[1]); 

thank’s ring0 & w3schools
http://www.w3schools.com/jsref/jsref_obj_regexp.asp

but there is problem ! it doesn’t work with

aa<p><span>Hello</span></p>aa
  • 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-05-16T17:19:10+00:00Added an answer on May 16, 2026 at 5:19 pm

    A regular expression that takes care of removing p attributes

    var new = text.replace(/^<p[^>]*>(.*)<\/p>$/i, "$1");
    

    Or a version with .*?

    var new = text.replace(/^<p.*?>(.*)<\/p>$/i, "$1");
    

    And if <pre> or <param> may start the text, you have to prevent a match

    var new = text.replace(/^<p\b.*?>(.*)<\/p>$/i, "$1");
    

    edit to answer your second question

    To remove whatever is before / after

    var new = text.replace(/^.*<p\b[^>]*>(.*)<\/p>.*$/i, "$1");
    

    But if you want to remove all <p...> and all </p>, you should use the two lines

    var new = text.replace(/<p\b.*?>/ig, "");
    new = text.replace(/<\/p>/ig, "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is Join() in jquery? for example: var newText = $(p).text().split( ).join(</span> <span>);
I have a div editablecontent, which has the following code <span id=id1>Hello </span> <span
Here is an example: <div><span style=font-size:15px;>some text here which is </span> <span style=color:red;>split automatically
i make this function : function price(val){ var test = $('span.hikashop_product_price_full:visible').text(); var test2 =
I am trying to split a string in javascript . it works fine in
how to split an array index i.e.. sample code var parts = currentVal.split( );
Does System.String.Split() ever return null ? (.NET) I know I've been coding in the
I'm using lettering.js to wrap <span> elements around each letter in a string. I'm
I am increasingly aware that my code in any single file can often span
I have the following code: $(input[id^='Order_'], input[id^='Default_']) .change(function (e) { var type = $(this).attr('id').split('_')[0];

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.