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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:18:55+00:00 2026-05-20T06:18:55+00:00

I have a regex like this (?<!(\w/))$#Cannot end with a word and slash I

  • 0

I have a regex like this

(?<!(\w/))$#Cannot end with a word and slash

I would like to extract the comment from the end. While the example does not reflect this case, there could be a regex with includes regex on hashes.

\##value must be a hash

What would the regex be to extract the comment ensuring it is safe when used against regex which could contain #’s that are not comments.

  • 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-20T06:18:56+00:00Added an answer on May 20, 2026 at 6:18 am

    Here’s a .Net flavored Regex for partly parsing .Net flavor patterns, which should get pretty close:

    \A
    (?>
        \\.         # Capture an escaped character
        |           # OR
        \[\^?       # a character class
            (?:\\.|[^\]])*    # which may also contain escaped characters
        \]
        |           # OR
        \(\?(?# inline comment!)\#      
            (?<Comment>[^)]*)
        \)
        |           # OR
        \#(?<Comment>.*$)   # a common comment!
        |           # OR
        [^\[\\#]    # capture any regular character - not # or [
    )*
    \z
    

    Luckily, in .Net each capturing group remembers all of its captures, and not just the last, so we can find all captures of the Comment group in a single parse. The regex pretty much parses regular expression – but hardly fully, it just parses enough to find comments.
    Here’s how you use the result:

    Match parsed = Regex.Match(pattern, pattern,
                               RegexOptions.IgnorePatternWhitespace | 
                               RegexOptions.Multiline);
    if (parsed.Success)
    {
        foreach (Capture capture in parsed.Groups["Comment"].Captures)
        {
            Console.WriteLine(capture.Value);
        }
    } 
    

    Working example: http://ideone.com/YP3yt

    One last word of caution – this regex assumes the whole pattern is in IgnorePatternWhitespace mode. When it isn’t set, all # are matched literally. Keep in mind the flag might change multiple times in a single pattern. In (?-x)#(?x)#comment, for example, regardless of IgnorePatternWhitespace, the first # is matched literally, (?x) turns the IgnorePatternWhitespace flag back on, and the second # is ignored.

    If you want a robust solution you can use a regex-language parser.
    You can probably adapt the .Net source code and extract a parser:

    • Reference Source – RegexParser.cs
    • GitHub – RegexParser.cs
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this regex ((.*?)(\(.*?\))|(.*?)) I would like to remove the | as i
I have some Regex, it looks like this: string regexForDrop = @^((%27)|'|(\-\-))\s*(d|%64|%44)(r|%72|%52)(o|%6F|%4F)(p|%70|%50)$; It works
I have a value like this: Foo Bar Another Value something else What regex
I have a lines like this NF419andZNF773 (e=10^-92,). ZNF571 (e=2 10^-14,) What's the regex
Let's say I have two strings like this: XABY XBAY A simple regex that
I have a binary file that I would like to regex search/replace hex bytes
Does anyone use have a good regex library that they like to use? Most
I have the following regex in PHP: /(?<=\')[^\'\s][^\']*+(?=\')|(?<=)[^\s][^]*+(?=)|[^\',\s]+/ and I would like to port
I would like to match dotall and non-greedy. This is what I have: img(.*?)(onmouseover)+?(.*?)a
I have this regex in a query in postgres and I cannot figure out

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.