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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:28:12+00:00 2026-05-22T21:28:12+00:00

Not a complete newbie, but I still don’t understand everything about Regular expressions. I

  • 0

Not a complete newbie, but I still don’t understand everything about Regular expressions. I was trying to use Regex to strip out <p> tags and my first attempt

<p\s*.*>

was so greedy it caught the whole line

<p someAttributes='example'>SomeText</p>

I got it to work with

((.|\s)*?)

This seems like it should be just as greedy, can anyone help me understand why it isnt?

Trying to make this question as language non-specific as possible, but I was doing this with ColdFusion’s reReplaceNoCase if it makes a lot of difference.

  • 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-22T21:28:12+00:00Added an answer on May 22, 2026 at 9:28 pm

    The key difference is the *? part, which creates a reluctant quantifier, and so it tries to match as little as possible. The standard quantifier * is a greedy quantifier and tries to match as much as possible.

    See e.g. Greedy vs. Reluctant vs. Possessive Quantifiers

    As Seth Robertson noted, you might want to use a regex that does not depend on the greedy/reluctant behaviour. Indeed, you can write a possessive regex for best performance:

    <p\s*+[^>]*+>
    

    Here, \s*+ matches any number of white space, while [^>]*+ matches any number of characters except >. Both quantifiers do not track back in case of a mismatch, which improves runtime in case of a mismatch, and for some regex implementations also in case of a match (because internal backtracking data can be omitted).

    Note that, if there are other tags starting with <p (didn’t write HTML directly for a long time), you match these too. If you don’t want that, use a regex like this:

    <p(\s++[^>]*+)?>
    

    This makes the whole section between <p and > optional.

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

Sidebar

Related Questions

I'm not new to Python but a complete newbie with regular expressions (on my
I am a complete newbie to iOS development but not to programming. I am
I have a mysql problem, my query looks as follows but not complete SELECT
I'm reading the not so complete pytz documentation and I'm stuck on understand one
I'm not sure if this is possible (complete non-flash developer speaking), but we have
Sorry, I'm not even sure how to ask, since I'm a complete newbie at
I'm sorry, I'm a complete newbie to CSS and I'm trying to create a
Complete newbie in VS and C#, I am trying to setup a web service,
I am a complete PHP newbie, and I'm not even sure if I should
I'm a complete newbie at Haskell. I'm trying to compile this Haskell file I've

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.