Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regex pattern from "xml" like stuff

Posted on 2012-04-12
5
Medium Priority
?
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

721 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