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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:26:00+00:00 2026-05-22T18:26:00+00:00

I am trying to create a .NET Regex that will match quoted strings in

  • 0

I am trying to create a .NET Regex that will match quoted strings in VB.NET source code, but excluding certain unwanted strings, such as strings in XML comments and region labels etc.

Here’s a data sample, representing some VB.NET source code that the Regex might execute against:

#Region "Class Constructors"

''' <summary>
''' Initializes a new instance of the <see cref="MyClass" /> class.
''' </summary>
Public Sub New()
    Debug.WriteLine("This string should be matched by the Regex")
End Sub

#End Region

The Regex should match the quoted string in the Debug.WriteLine method call, but should ignore the string in the region label and the XML comment. It should also support VB.NET’s quote escaping syntax that uses two consecutive double quotes to represent an embedded (escaped) quote character:

"This is a string containing an escaped quote "" character"

As a starting point, I have experimented with the following Regex, but the negative lookbehind causes it to match subsequent closing quotes as if they were opening quotes.

(?<!Region\s+)"(?<Literal>(?:[^"]|"")*)"

As an additional finesse, it would be helpful if the Regex could completely ignore empty strings represented by a pair of quote characters.

Any suggestions please?

Thanks in advance,
Tim

  • 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-22T18:26:01+00:00Added an answer on May 22, 2026 at 6:26 pm

    I think this is one of the cases where a single regex won’t solve all of your problems. I assume that #Region directives can be multi-lined as in:

    #Region \
      "MyRegion"
    

    or maybe with some other line break character, so your lookbehind isn’t enough at all. Extracting matches selectively from a text with a complex syntax requires a lexer, or maybe you should parse the whole thing differently.
    You might however be able to find a shortcut, for example you know that you don’t want anything between the tags <summary> and </summary>, so you can loop through each line and skip everything past <summary> until you find the closing tag, then you can resume matching for strings.
    You should put special care in writing a regex to strip comments and preprocessor directives away (ie: ‘, # and REM). Note that those keywords are all valid when they’re not in a string, so stripping comments is a bit involved. Even there, a single regex might not be enough.
    For dropping double quotes, this seems to do the trick for me:

    "((?:[^"]|"")+)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a .Net Regex that will separate an Excel header
I am trying to create a .NET RegEx expression that will properly balance out
I am trying to create a regex that will take all files that do
We're trying to create a .NET aspx page that will have a PDF within
I'm trying to create a .net charting control completely in the code behind and
I am trying to create an asp.net web form that allows a user to
I'm trying to create a Zip file from .Net that can be read from
I am trying to create a .NET Regex to parse a CSS font declaration,
I am trying to create a regex validation attribute in asp.net mvc to validate
I'm trying to create an ASP.NET/C# page that allows the user to edit 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.