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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:29:29+00:00 2026-05-10T16:29:29+00:00

Is it possible to detect a valid regular expression with another regular expression? If

  • 0

Is it possible to detect a valid regular expression with another regular expression? If so please give example code below.

  • 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-10T16:29:30+00:00Added an answer on May 10, 2026 at 4:29 pm
    / ^                                             # start of string (                                             # first group start   (?:     (?:[^?+*{}()[\]\\|]+                      # literals and ^, $      | \\.                                    # escaped characters      | \[ (?: \^?\\. | \^[^\\] | [^\\^] )     # character classes           (?: [^\]\\]+ | \\. )* \]      | \( (?:\?[:=!]|\?<[=!]|\?>)? (?1)?? \)  # parenthesis, with recursive content      | \(\? (?:R|[+-]?\d+) \)                 # recursive matching      )     (?: (?:[?+*]|\{\d+(?:,\d*)?\}) [?+]? )?   # quantifiers   | \|                                        # alternative   )*                                          # repeat content )                                             # end first group $                                             # end of string / 

    This is a recursive regex, and is not supported by many regex engines. PCRE based ones should support it.

    Without whitespace and comments:

    /^((?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>)?(?1)??\)|\(\?(?:R|[+-]?\d+)\))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*)$/ 

    .NET does not support recursion directly. (The (?1) and (?R) constructs.) The recursion would have to be converted to counting balanced groups:

    ^                                         # start of string (?:   (?: [^?+*{}()[\]\\|]+                   # literals and ^, $    | \\.                                  # escaped characters    | \[ (?: \^?\\. | \^[^\\] | [^\\^] )   # character classes         (?: [^\]\\]+ | \\. )* \]    | \( (?:\?[:=!]          | \?<[=!]          | \?>          | \?<[^\W\d]\w*>          | \?'[^\W\d]\w*'          )?                               # opening of group      (?<N>)                               #   increment counter    | \)                                   # closing of group      (?<-N>)                              #   decrement counter    )   (?: (?:[?+*]|\{\d+(?:,\d*)?\}) [?+]? )? # quantifiers | \|                                      # alternative )*                                        # repeat content $                                         # end of string (?(N)(?!))                                # fail if counter is non-zero. 

    Compacted:

    ^(?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>|\?<[^\W\d]\w*>|\?'[^\W\d]\w*')?(?<N>)|\)(?<-N>))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*$(?(N)(?!)) 

    From the comments:

    Will this validate substitutions and translations?

    It will validate just the regex part of substitutions and translations. s/<this part>/.../

    It is not theoretically possible to match all valid regex grammars with a regex.

    It is possible if the regex engine supports recursion, such as PCRE, but that can’t really be called regular expressions any more.

    Indeed, a ‘recursive regular expression’ is not a regular expression. But this an often-accepted extension to regex engines… Ironically, this extended regex doesn’t match extended regexes.

    ‘In theory, theory and practice are the same. In practice, they’re not.’ Almost everyone who knows regular expressions knows that regular expressions does not support recursion. But PCRE and most other implementations support much more than basic regular expressions.

    using this with shell script in the grep command , it shows me some error.. grep: Invalid content of {} . I am making a script that could grep a code base to find all the files that contain regular expressions

    This pattern exploits an extension called recursive regular expressions. This is not supported by the POSIX flavor of regex. You could try with the -P switch, to enable the PCRE regex flavor.

    Regex itself ‘is not a regular language and hence cannot be parsed by regular expression…’

    This is true for classical regular expressions. Some modern implementations allow recursion, which makes it into a Context Free language, although it is somewhat verbose for this task.

    I see where you’re matching []()/\. and other special regex characters. Where are you allowing non-special characters? It seems like this will match ^(?:[\.]+)$, but not ^abcdefg$. That’s a valid regex.

    [^?+*{}()[\]\\|] will match any single character, not part of any of the other constructs. This includes both literal (a – z), and certain special characters (^, $, .).

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have created a self generated certificate to sign a DLL. When I load
Background I have an application written in native C++ over the course of several
I'm working on an application where users have to make a call and type
I have a graph with n nodes as an adjacency matrix . Is it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.