473,394 Members | 1,971 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,394 software developers and data experts.

Counting regex expressions

Hi,
I'm getting into a tangle with Regex in C#.

If I had an expression like abc[1].def[2].ghi[3] etc.

How do I count how many instances there are of "[ ]" and "."

Thanks a lot!

TH

Jan 19 '07 #1
3 1630
tr***************@btinternet.com wrote:
If I had an expression like abc[1].def[2].ghi[3] etc.

How do I count how many instances there are of "[ ]" and "."
Use the regex @" \[ \s* \d+ \s* \] " with the IgnorePatternWhitespace
option; call Matches; and read the Count property.

--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
Jan 19 '07 #2

Jon Shemitz wrote:
tr***************@btinternet.com wrote:
If I had an expression like abc[1].def[2].ghi[3] etc.

How do I count how many instances there are of "[ ]" and "."

Use the regex @" \[ \s* \d+ \s* \] " with the IgnorePatternWhitespace
option; call Matches; and read the Count property.

--

.NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
Could I do it like this?

// Assume Key is of the form a.b.c.d.e.f

Match n = Regex.Match( key, @"\." );

int noOfMatches = n.Count;

Jan 19 '07 #3
tr***************@btinternet.com wrote:
Could I do it like this?

// Assume Key is of the form a.b.c.d.e.f

Match n = Regex.Match( key, @"\." );

int noOfMatches = n.Count;
Not quite - the Match object represents a single match, and doesn't
have a Count property. You want the Matches method, not the Match
method:

int NumberOfDots = Regex.Matches(Key, @"\.").Count;

--

..NET 2.0 for Delphi Programmers
www.midnightbeach.com/.net
Jan 19 '07 #4

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

Similar topics

8
by: Johnny | last post by:
I need to determine whether a text box contains a value that does not convert to a decimal. If the value does not convert to a decimal, I want to throw a MessageBox to have the user correct the...
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 ...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
5
by: lgbjr | last post by:
Hello All, I have the following type of string: "X:Y\Z.exe" "123" What I need is an array of strings with the information from within each set of quotes. I was trying to use a Regex.Split, but...
2
by: Art | last post by:
Hi & help, I'm trying to parse arithmetic expressions such as 4*(7-2.1). The first thing I'm trying is to add spaces to get: 4 * ( 7 - 2.1 ). I thought that Regular Expressions would be the...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
1
by: Terry Olsen | last post by:
I download xml logs from several servers every day and read the data out of them using the XmlTextReader. But about 10% of them each day throw exceptions because they are not well formed. I don't...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.