Solved

Regex pattern from "xml" like stuff

Posted on 2012-04-12
5
527 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 143

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 143

Author Closing Comment

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

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

828 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