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

The Archive Base Latest Questions

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

I need to find attribute values in an ASPX file using regular expressions. That

  • 0

I need to find attribute values in an ASPX file using regular expressions.

That means you don’t need to worry about malformed HTML or any HTML related issues.

I need to find the value of a particular attribute (LocText). I want to get what’s inside the quotes.
Any ASPX tags such as <%=, <%#, <%$ etc. inside the value don’t make sense for this attribute therefore are considered as part of it.

The regex I began with looks like this:

LocText="([^"]+)"

This works great, the first group, which is the result text, gets everything except the double quotes, which are not allowed there (&quot ; must be used instead)

But the ASPX file allows using of single quotes – second regular expression must be applied then.

LocText='([^']+)'

I could use these two regular expressions but I’m looking for a way to connect them.

LocText=("([^"]+)"|'([^']+)')

This also works but doesn’t seem very efficient as it’s creating unnecessary number of groups. I think this could be somehow done by using backreferences, but I can’t get it to work.

LocText=(["']{1})([^\1]+)\1

I thought that by this, I save the single/double quote to the first group and then I tell it to read anything that is NOT the char found in the first group. This is enclosed again by the quote from the first group. Obviously, I’m wrong and it’s not working like that.

Is there any way, how to connect the first two expressions together creating just a minimum amount of groups with one group being the value of the attribute I want to get? Is it possible using a backreference for the single/double quote value, or have I completely misunderstood the meaning of them?

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

    I’d say your solution with alternation isn’t that bad, but you could use named captures so the result will always be found in the same group’s value:

    Regex regexObj = new Regex(@"LocText=(?:""(?<attr>[^""]+)""|'(?<attr>[^']+)')");
    resultString = regexObj.Match(subjectString).Groups["attr"].Value;
    

    Explanation:

    LocText=          # Match LocText=
    (?:               # Either match
     "(?<attr>[^"]+)" # "...", capture in named group <attr>
    |                 # or match
     '(?<attr>[^']+)' # '...', also capture in named group <attr>
    )                 # End of alternation
    

    Another option would be to use lookahead assertions ([^\1] isn’t working because you can’t place backreferences inside a character class, but you can use them in lookarounds):

    Regex regexObj = new Regex(@"LocText=([""'])((?:(?!\1).)*)\1");
    resultString = regexObj.Match(subjectString).Groups[2].Value;
    

    Explanation:

    LocText=   # Match LocText=
    (["'])     # Match and capture (group 1) " or '
    (          # Match and capture (group 2)...
     (?:       # Try to match...
      (?!\1)   # (unless it's the quote character we matched before)
      .        # any character
     )*        # repeat any number of times
    )          # End of capturing group 2
    \1         # Match the previous quote character
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find random nodes according to random attribute values. To do that
I need to find/create an application that will create employee web usage reports from
I need to find all occurrences of a function call in a C++ file
I have amount attribute in coredata model with string datatype. I need to find
I need to parse an xml string and find values of specific text nodes,
I need to find a way to show the value of a custom attribute
I need to select a link node given its url. Using an attribute selector
From some xml I want to find items that have a specific attribute and
I need to compare some Rails (2.3.11) model attribute values before and after a
I need to find out how to format numbers as strings. My code is

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.