Sign in to follow this  
Mike

[C#] Regular Expressions...

Recommended Posts

I've got strings that are two digits seperated by any number/type of white space(s). For example "99 \t\t 104" (\t = tab) I know that I can use "\d+\s+\d+" to represent such a string. Now what I'm wondering is what is the proper way to split up the string into each of it's components in C#? I know i could use Regex.Split( input, "\s+" ) to split it inbetween the letters, but there seems to me that there should be a better way to give C# a regular expression, tell it to find a match (which can be down with Regex.Match) and then find out exactly what each part of the match is. I would think the Match returned by Regex.Match would have this information, but where? Thanks.

Share this post


Link to post
Share on other sites
Regex.Match will only return the first match it finds, Regex.Matches will return all of the matches in a string.
the Match class contains the index of the first match in the original string, along with a collection of Groups that represents each of the groups matched by the regular expression, see: Match class, All members

P.S. This should be in the .net forum.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this