[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

c# regex Match variable number of strings

Posted on 2014-01-07
2
Medium Priority
?
736 Views
Last Modified: 2014-01-08
Hi,
The following regex code will match two strings which fall in between ">" and "<":
--------
string rawReview = "aaaaaaaa>string1<bbbbbbb>string2<cccccccc";
           
match = Regex.Match(rawReview, @">([^<]*).*?>([^<]*)");
if (match.Success)
{
    Console.Write("Match found  {0} {1}\n", match.Groups[1], match.Groups[2]);
}
--------
Match found string1 string2

I would like to extend this example to be able to match an arbitrary number of strings which fall between the bracket chars.  Is this possible?  

Thank you very much for reading and considering my question.
0
Comment
Question by:97WideGlide
[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 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 39764616
Try this:
            match = Regex.Match(rawReview, @">([^<]*)");
            while (match.Success) {
                Console.Write("Match found  {0}\n", match.Groups[1]);
                match = match.NextMatch();
            }

Open in new window

0
 
LVL 8

Author Closing Comment

by:97WideGlide
ID: 39765096
Simple when you know what you're doing.  I solved it last night after two hours using a MatchCollection which clearly wasn't necessary.  Your solution taught me a bit about regular expressions.

Thank you very much.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Many of the most common information processing tasks require sorting data sets.  For example, you may want to find the largest or smallest value in a collection.  Or you may want to order the data set in numeric or alphabetical order. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

649 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