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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:55:46+00:00 2026-05-25T05:55:46+00:00

I need to use .NET regular expressions to scrap some values between <value> tags

  • 0

I need to use .NET regular expressions to scrap some values between <value> tags of a markup file such as this (copy\pasted excerpt):

<Title>Section1</Title>

<attributeArray><name>Name1</name><value>Value1</value></attributeArray>

<attributeArray><name>Name2</name><value>Value2</value></attributeArray>

<attributeArray><name>Name3</name><value>Value3</value></attributeArray>

<attributeArray><name>Name4</name><value>Value4</value></attributeArray>

<Title>Section2</Title>

<attributeArray><name>Name1</name><value>Value1</value></attributeArray>

<attributeArray><name>Name2</name><value>Value2</value></attributeArray>

<attributeArray><name>Name3</name><value>Value3</value></attributeArray>

<attributeArray><name>Name4</name><value>Value4</value></attributeArray>

</node>

The actual text goes on to include 6 sections. the problem I have is that all tag names for each section are identical and I only need to extract the values from say Section2 (so not including 1, 3,4,5,6).

I have struggled with this for a couple days and tried various conditional expressions which was new to me like this:

(?(<node>Section2)(.*?<value>(?<Value>.*?)<\/value>.*?))

If Section 2, then parse the value keys, but it only extracts the first value – it does not iterate through each <value> of the markup. and the markup usually has around 10 values that I need to extract (abbreviated in the example above).

This is not being done in code so I don’t have the liberty of using an XML parser.

Any suggestions would be greatly appreciated – or if I can clarify further let me know.

an afterthought- if there is a way to include the text of the title with each value match then I could parse all 6 sections, but I could later filter the result based on the section I am after would also work.

example:

match1
group1 = Section2
group2 = Value1

match2
group1 = Section2
group2 = Value2

match3
group1 = Section2
group2 = Value3

match4
group1 = Section2
group2 = Value4

Thanks!

  • 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-25T05:55:47+00:00Added an answer on May 25, 2026 at 5:55 am

    Here’s one option:

    (?:
       <Title>Section2</Title>    # Match the header
       |                          # or
       \G(?!\A)                   # Match where the previous match ended
    )\s*
    <attributeArray>
        <name>(?<name>[^<]*)</name>
        <value>(?<value>[^<]*)</value>
    </attributeArray>
    

    The first match includes the header, and the following matches must start where the previous one ended.
    Working example: http://regexhero.net/tester/?id=321ce843-923d-4556-9b99-dbb72175929a


    Note that the above will fail if you have other elements you didn’t mention between the values or the title. You can get around that with a probably less efficient pattern, using the fact .Net regexes can have variable length lookbehinds:

    (?<=                          # lookbehind - check that before the current position
       <Title>Section2</Title>    #  we can see the wanted title,
       (?:(?!<Title>).)*          #  followed by no more title between it and here.
    )
    <attributeArray>
        <name>(?<name>[^<]*)</name>
        <value>(?<value>[^<]*)</value>
    </attributeArray>
    

    Example: http://regexhero.net/tester/?id=743c4de6-1b8a-48a4-a69b-63f3624de594

    If you want to, you can change the title to <Title>(?<title>[^<]*)</Title>, capture all values in the file, and filter by the wanted title – it will be added to each match.


    Lastly, here’s a similar approach which will work in other flavors: it captures key/value pairs before the title Section3, assuming it is well ordered:

    <attributeArray>
        <name>(?<name>[^<]*)</name>
        <value>(?<value>[^<]*)</value>
    </attributeArray>
    (?=
       (?:(?!<Title>).)*
       <Title>Section3</Title>
    )
    

    Example: http://regexhero.net/tester/?id=8d8ae0e8-5f10-439f-a5a5-50d0b4e73bd2

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

Sidebar

Related Questions

Using ASP.NET MVC + jQuery : I need to use some values owned by
I need some help with regular expressions please. (In .Net 4 and C#) I
I have some ASP.NET Master Pages located in one assembly. I need to use
I need a regular expression that I can use in VBScript and .NET that
I have a syntax highlighting function in vb.net. I use regular expressions to match
I need help with a regular expression for use with UrlRewriting.Net. I have two
I need an up to date and easy to use .net wrapper for google
I need to use one of my VB.NET projects in a C++ project. The
I need to use a dll in my asp.net application. How do I load
I use a System.Timers.Timer in my Asp.Net application and I need to use the

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.