Solved

Regex pattern from "xml" like stuff

Posted on 2012-04-12
5
523 Views
Last Modified: 2012-08-14
say we have this string:
<sql>abc</sql><parameter><name>smsc</name><value>62000</value></parameter><parameter><name>msisdn</name><value>123456789</value></parameter><parameter><name>message</name><value>test proc</value></parameter><parameter><name>sourcename</name><value>test</value></parameter>

Open in new window

I want with the Regex.Matches to return the MatchCollection to return all the <parameter>...</parameter> parts.

my first tries was:
<parameter>(.*)</parameter>

Open in new window

which returns this:
<parameter><name>smsc</name><value>62000</value></parameter><parameter><name>msisdn</name><value>123456789</value></parameter><parameter><name>message</name><value>test proc</value></parameter><parameter><name>sourcename</name><value>test</value></parameter>

Open in new window

matching the first <parameter> with the last </parameter> :(

I think this should be quite obvious ...
note: I won't care about people telling me to parse this with xml document or the like ...
I know the arguments, and have my reasons to work like this ...

thanks
0
Comment
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:pfrancois
ID: 37837572
0
 
LVL 142

Author Comment

by:Guy Hengel [angelIII / a3]
ID: 37837730
with due respect, but I thought I had made clear that:
note: I won't care about people telling me to parse this with xml document or the like ...
I know the arguments, and have my reasons to work like this ...
0
 
LVL 10

Expert Comment

by:pfrancois
ID: 37838221
Your choice...
0
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 37838820
Please try the following:
<parameter>(.*?)</parameter>

Open in new window

0
 
LVL 142

Author Closing Comment

by:Guy Hengel [angelIII / a3]
ID: 37841304
small but efficient change.
thanks!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now