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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:11:11+00:00 2026-05-24T11:11:11+00:00

Is there a specification in the form of a perl regular expression that will

  • 0

Is there a specification in the form of a perl regular expression that will match all perl regular expression literals?

Failing that, is there a specification in any language for all perl regular expression literals?

Ideally, it should include regular expression modifiers like /x and regular expression operators like s/, but I could tack those on later.

Specifications that match after variable interpolation are ideal, but before is fine too.

Context: I am writing in perl (Actually, using Parse::RecDescent) a metalanguage that compiles into perl, and want to identify regular expression literals and pass them on to perl.

  • 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-24T11:11:12+00:00Added an answer on May 24, 2026 at 11:11 am

    Those operators can contain arbitrary Perl code, and there’s no specification for that.

    For example, in

    /$x{ EXPR }/
    

    and

    s// EXPR /e
    

    EXPR can be almost any valid Perl expression.

    However, I don’t think you actually need to know how to parse it. You just need to know where it ends. And that’s rather easy. Perl also needs to be able to do that before it can parse the operator, so it disallows certain code patterns. (Thus the “almost” above.)

    • Any occurrences of the delimiter must be preceded by an odd number of “\“.

    • As an exception to the above, when the delimiter is (), [] or {}, the delimiters may appear unescaped as long as they are balanced.

    balanced_paren_guts  : ( /(?:[^\\\(\)]|\\.)+/ | '(' balanced_paren_guts  ')' )(s?)
    balanced_square_guts : ( /(?:[^\\\[\]]|\\.)+/ | '[' balanced_square_guts ']' )(s?)
    balanced_curly_guts  : ( /(?:[^\\\{\}]|\\.)+/ | '{' balanced_curly_guts  '}' )(s?)
    
    
    match_op        : <skip:> 'm' /\s*/ match_op_1 match_modifiers
    
    match_op_1      : '(' <commit> balanced_paren  ')'
                    | '[' <commit> balanced_square ']'
                    | '{' <commit> balanced_curly  '}'
                    | /(?x: ([^\\]) (?:(?!\1).|\\.)* \1 )/
    
    match_modifiers : /\w+/
    
    
    subst_op        : <skip:> 's' /\s*/ subst_op_1 subst_modifiers
    
    subst_op_1      : '(' <commit> balanced_paren  ')' \s* subst_op_2
                    | '[' <commit> balanced_square ']' \s* subst_op_2
                    | '{' <commit> balanced_curly  '}' \s* subst_op_2
                    | /(?x: ([^\\]) (?:(?!\1).|\\.)* \1 (?:(?!\1).|\\.)* \1 )/
    
    subst_op_2      : '(' <commit> balanced_paren  ')'
                    | '[' <commit> balanced_square ']'
                    | '{' <commit> balanced_curly  '}'
                    | /(?x: ([^\\]) (?:(?!\1).|\\.)* \1 )/
    
    subst_modifiers : /\w+/
    

    Notes:

    • The rules may not correctly handle «'» as a delimiter.
    • A rule needs to be added to allow «\» as a delimiter, but I don’t think you should support that.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the Java Language Specification : If there are any enclosing try statements
I'm trying to find a regular expression for a URL that will be compliant
Is there a language specification for clojure? Something that precisely defines the lexical syntax
Is there any way to control and manual specification for start of teaser ?.
Are there any implementations of the WS-Discovery specification for JAX-WS RI, Axis2, CXF or
Is there a way to use a match specification to select between different clauses
Is there any difference in using non-capticalized post or capitalized POST in <form> action
If I write: char arr[8] = abc; Is there any specification over what arr[4]
There are numerous places on the Internet, suggesting that it is easily achieved by
I'm using specifications in this kind of form: public static Expression<Func<User, bool>> IsSuperhero {

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.