473,382 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Regex match multiple per line

I have the following regex that I am using:

Match match = Regex.Match(global, "%(?<column>.+?)%");

my input string (global) is this:
"something\%username%\somethingelse\%match2%\some\ %match3%

I want it to match "username","match2" and "match3"

but it only matches %username%, it doesnt continue on and get the other
matches

match.Groups.Count is equal to 2, which i assume, 0 is the whole string
and 1 is "%username%

How do I get it so it matches all of the strings between %%

thanks

dkode

Nov 17 '05 #1
1 5133
"DKode" <dk****@gmail.com> wrote in
news:11**********************@g14g2000cwa.googlegr oups.com:
I have the following regex that I am using:

Match match = Regex.Match(global, "%(?<column>.+?)%");

my input string (global) is this:
"something\%username%\somethingelse\%match2%\some\ %match3%

I want it to match "username","match2" and "match3"

but it only matches %username%, it doesnt continue on and get
the other matches

match.Groups.Count is equal to 2, which i assume, 0 is the whole
string and 1 is "%username%

How do I get it so it matches all of the strings between %%


dkode,

Use a MatchCollection object and the Regex.Matches method:
MatchCollection matches = Regex.Matches(global, "%(?<column>.+?)%");

foreach (Match m in matches)
Console.WriteLine(m.Groups["column"].ToString());
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Felix Schwarz | last post by:
Hi all, I'm experiencing problems with a regular expression and I can't figure out which words I use when googling. I read the python documentation for the re module multiple times now but still...
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
2
by: Daniel Billingsley | last post by:
First, if MSFT is listening I'll say IMO the MSDN material is sorely lacking in this area... it's just a whole bunch of information thrown at you and you're left to yourself as to organizing it in...
5
by: Tap | last post by:
I would like to parse the following string with as little code as possible. stringValue = "Email Message ID:TAPASVI to...
2
by: John Baro | last post by:
I need to determine when multiple fonts are selected in a richtextbox. A font is indicated by \fcharset(N) where (N) is a number. (To the best of my knowledge) I can use this statement int...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
6
by: Lubomir | last post by:
Hi, I am using the following pattern: "\\b" + MySttring + "\\b" If MyString is "one", this should pick up whole words like "one". The problem is, it will pick up also the word: "one.two"...
3
by: Hrvoje Niksic | last post by:
I often have the need to match multiple regexes against a single string, typically a line of input, like this: if (matchobj = re1.match(line)): ... re1 matched; do something with matchobj ......
2
by: John B | last post by:
I am trying to do a pretty simple pattern match using regex. The pattern is ^(?:(?<Item>.*?)@:@)*$. This should return a match for test123@:@ but does not, instead it never returns when I call...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.