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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:00:39+00:00 2026-06-07T02:00:39+00:00

Here on SO people sometimes say something like you cannot parse X with regular

  • 0

Here on SO people sometimes say something like “you cannot parse X with regular expressions, because X is not a regular language”. From my understanding however, modern regular expressions engines can match more than just regular languages in Chomsky’s sense. My questions:

given a regular expression engine that supports

  • backreferences
  • lookaround assertions of unlimited width
  • recursion, like (?R)

what kind of languages can it parse? Can it parse any context-free language, and if not, what would be the counterexample?

(To be precise, by “parse” I mean “build a single regular expression that would accept all strings generated by the grammar X and reject all other strings”).

Add.: I’m particularly interested to see an example of a context-free language that modern regex engines (Perl, Net, python regex module) would be unable to parse.

  • 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-07T02:00:41+00:00Added an answer on June 7, 2026 at 2:00 am

    I recently wrote a rather long article on this topic: The true power of regular expressions.

    To summarize:

    • Regular expressions with support for recursive subpattern references can match all context-free languages (e.g a^n b^n).
    • Regular expressions with lookaround assertions and subpattern references can match at least some context-sensitive languages (e.g. ww and a^n b^n c^n).
    • If the assertions have unlimited width (as you say), then all context-sensitive grammars can be matched. I don’t know any regex flavor though that does not have fixed-width restrictions on lookbehind (and at the same time supports subpattern references).
    • Regular expressions with backreferences are NP-complete, so any other NP problem can be solved using regular expressions (after applying a polynomial-time transformation).

    Some examples:

    • Matching the context-free language {a^n b^n, n>0}:

      /^(a(?1)?b)$/
      # or
      /^ (?: a (?= a* (\1?+ b) ) )+ \1 $/x
      
    • Matching the context-sensitive language {a^n b^n c^n, n>0}:

      /^
          (?=(a(?-1)?b)c)
          a+(b(?-1)?c)
      $/x
      # or
      /^ (?: a (?= a* (\1?+ b) b* (\2?+ c) ) )+ \1 \2 $/x
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like many people here, I started my programming experience with the good ol' green
It seems like a lot of people here and on many programmer wikis/blogs/ect. elsewhere
I often hear around here from test driven development people that having a function
In code, I sometimes see people specify constants in hex format like this: const
I know using goto is something most people say to avoid, however I have
I have read a lot of topic here and people tend to store IP
Some time ago, people here helped me very well with code. Now I'm tasked
I used to have tables before to display the content and people here advised
Here and there people keep talking about memory leaks which occur due unreleased event
Here a lot of people are confused, Normal class stores its data in the

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.