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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:16:17+00:00 2026-05-10T21:16:17+00:00

I have this naive regex "<([\s]|[^<])+?>" (excluding the quotation marks). It seems so straightforward

  • 0

I have this naive regex "<([\s]|[^<])+?>" (excluding the quotation marks). It seems so straightforward but it is indeed evil when it works against the below HTML text. It sends the Java regular expression engine to an infinite loop.

I have another regex ("<.+?>"), which does somewhat the same thing, but it doesn’t kill anything. Do you know why this happens?

<script language="JavaScript" type="text/javascript">         var numDivs, layerName;         layerName = "lnavLayer";         catLinkName = "category";         numDivs = 2;         function toggleLayer(layerID){             if (!(navigator.appName == "Netscape" && navigator.appVersion.substr(0, 1) < 5)){                 thisLayer = document.getElementById(layerName + layerID);                 categoryLink = document.getElementById(catLinkName + layerID);                 closeThem();                 if (thisLayer.className == 'subnavDefault'){                     thisLayer.className = 'subnavToggled';                     categoryLink.className = 'leftnavLinkSelectedSection';                 }             }         }         function closeThem(){             for(x = 0; x < numDivs; x++){                 theLayer = document.getElementById(layerName + (x + 1));                 thecategoryLink = document.getElementById(catLinkName + (x + 1));                 theLayer.className = 'subnavDefault';                 thecategoryLink.className = 'leftnavLink';             }         } var flag = 0; var lastClicked = 0     //-->     </script> 

it even keeps looping with an online Java regex tool (such as http://www.fileformat.info/tool/regex.htm) or a utility like RegexBuddy.

  • 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. 2026-05-10T21:16:18+00:00Added an answer on May 10, 2026 at 9:16 pm

    The reason the Java regex engine crashes is that this part of your regex causes a stack overflow (indeed!):

    [\s]|[^<] 

    What happens here is that every character matched by \s can also be matched by [^<]. That means there are two ways to match each whitespace character. If we represent the two character classes with A and B:

    A|B 

    Then a string of three spaces could be matched as AAA, AAB, ABA, ABB, BAA, BAB, BBA, or BBB. In other words the complexity of this part of the regex is 2^N. This will kill any regex engine that doesn’t have any safeguards against what I call catastrophic backtracking.

    When using alternation (vertical bar) in a regex, always make sure the alternatives are mutually exclusive. That is, at most one of the alternatives may be allowed to match any given bit of text.

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

Sidebar

Related Questions

This question might be naive as I'm new to ColdFusion programming. I have a
This is probably a multi-part question. Background: we have a native (c++) library that
Quick question. I have an app that use a native DLL through PInvoke, this
Have this query: SELECT HOUR( DATE ) AS hr, COUNT( * ) AS cnt
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have this array in PHP: array( [0] => array( 'username' => 'user1' )
We have this software that has a webservices component. Now, the administrator of this
I have this error message: Msg 8134, Level 16, State 1, Line 1 Divide
I have this membership site setup on my local machine using the ASP.NET membership
I have this DependencyProperty which holds an entity with a property that is a

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.