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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:07:13+00:00 2026-06-11T10:07:13+00:00

I have two strings string a = text ‘text’ string b = ‘text text’

  • 0

I have two strings

string a = "text 'text'"
string b = 'text "text"'

In this language both the " and ' can be used to start and end a string literal, and they can contain the other symbol inside them (quotation marks are valid inside apostrophes, and vice versa)

I need a regex that can deal with both, currently I have:

(?:\"|')(?<content>[^\"']*)(?:\"|')

but used on string a, this would only give me "text ' and not the full string.

  • 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-11T10:07:15+00:00Added an answer on June 11, 2026 at 10:07 am

    The basic technique is:

    (["'])((?:(?!\1).)*)\1

    The opening quote is captured in group #1, and (?:(?!\1).)* matches zero or more of any character except the one that was captured. That’s enclosed in another set of capturing parens, so the contents are captured in group #2. Then the final \1 matches the closing quote.

    But you’re using a named group to capture the contents, so it’s probably best that you use named groups throughout (especially since you don’t say which flavor you’re using, and the interaction between named and numbered groups is not consistent from one flavor to the next). This should work in .NET or PHP:

    (?<quote>["'])(?<content>(?:(?!\k<quote>).)*)\k<quote>
    

    But if you’re using .NET I recommend using this instead:

    (?:"(?<content>[^"]*)"|'(?<content>[^']*)')
    

    Most flavors make it difficult or impossible to reuse group names within the same regex, but in .NET anything goes.

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

Sidebar

Related Questions

ok I have two strings. (I use this for a language library system to
I had two strings: <string name=bigtext>Big text</string> <string name=anothertext>Small text</string> I need them both
I have two MySQL tables, and I want to find and replace text strings
Suppose you have a string with text in two or more scripts. When you
I have two strings String s1=426F62; String s2=457665; The strings are in hex representation.
I have a basic program that compares two strings : #include <string> #include <iostream>
I have two strings str1 and str2 . Check both of them and see
I have two string variables which are both file paths. The code that worked
I have two strings: var str1 = '8***8***'; var str2 = '898-8293'; How can
I have two text blocks, containing company names. Both contain names of hundreds of

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.