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

Regex confusion

Hi,

I cannot seem to figure out how to construct a regex for what I need.

I need to match:

a

or

a.a.a.a // note: there can be any number of ".a" repetitions

or

a.*

or

a.a.a.a.*

where 'a' can be "one or more contiguous alpha chars".

The optional repetition is throwing me...

Any pointers are appreciated...

Thanks,
Tom
Nov 16 '05 #1
3 1285
"Tom Jones" <to********@hotmail.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
Hi,

I cannot seem to figure out how to construct a regex for what I need.

I need to match:

a

or

a.a.a.a // note: there can be any number of ".a" repetitions

or

a.*

or

a.a.a.a.*

where 'a' can be "one or more contiguous alpha chars".

The optional repetition is throwing me...


Does anyone see a problem with this: ^a(?:$|(?:\.a)*(?:\.\*)?)$

That seems to work but I don't know if I am missing something...

Tom
Nov 16 '05 #2
Hi Tom Jones,

I assume you want to get every "a." Try to do this:

A short example.

Codes:

using System;
using System.Text.RegularExpressions;

class RegEx
{
public static void Main()
{
MatchCollection mCollect;
String[] results = new String[20];
int[] mPosition = new int[20];

Regex r = new Regex("a.");
mCollect = r.Matches("a.c.a.a.a.a.a.a.f.g.g.ggg.c.a.");
for (int i = 0; i < mCollect.Count; i++)
{
results[i] = mCollect[i].Value;
Console.WriteLine(results[i]);
mPosition[i] = mCollect[i].Index;
Console.WriteLine(mPosition[i]);
}
}
}

Hope it helps. Correct me if i am wrong.
--
Regards,
Chua Wen Ching :)
"Tom Jones" wrote:
Hi,

I cannot seem to figure out how to construct a regex for what I need.

I need to match:

a

or

a.a.a.a // note: there can be any number of ".a" repetitions

or

a.*

or

a.a.a.a.*

where 'a' can be "one or more contiguous alpha chars".

The optional repetition is throwing me...

Any pointers are appreciated...

Thanks,
Tom

Nov 16 '05 #3
"Tom Jones" <to********@hotmail.com> wrote in
news:%2****************@tk2msftngp13.phx.gbl...
"Tom Jones" <to********@hotmail.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
...
Does anyone see a problem with this: ^a(?:$|(?:\.a)*(?:\.\*)?)$


I just entered this in expresso - seems to work fine. I don't think there is
a problem in that regex.

Niki
Nov 16 '05 #4

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

Similar topics

2
by: Will Clifton | last post by:
Hello, Spent all day yesterday reading about this and I still can't get it. Perhaps my IQ is not much above room temperature... My mySQL database is a simple inventory-type database with a...
8
by: John Hunter | last post by:
In trying to sdebug why a certain regex wasn't working like I expected it to, I came across this strange (to me) behavior. The file I am trying to match definitely contains many instances of the...
75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
9
by: Christ | last post by:
Hi there, i'm trying to make a regex, but it ain't working. In just one regex expression I want to check a password that must meet following requirements: - at least 6 characters long - at...
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...
3
by: DevBoy | last post by:
I am in need of parsing string based on characters like / or { or } or ^ However, anytime I try and run the following code I do not the proper results (It always returns the same string unparsed....
2
by: Tom Jones | last post by:
Hi, I have a component that accepts a string representing a class of files (exactly like those you would pass to the 'dir' dos command, ie. '*.txt', or '???.cpp'). An exception is generated...
7
by: Beeeeeeeeeeeeves | last post by:
Hi I do mostly programming in VB6 and C# although I like to dabble in C++ now and again, I was just wondering what is a good* regular expression library to use for C++, given that I DON'T want to...
17
by: Mark | last post by:
I must create a routine that finds tokens in small, arbitrary VB code snippets. For example, it might have to find all occurrences of {Formula} I was thinking that using regular expressions...
5
by: Jeff | last post by:
....hoping someone can help someone still new to vb.net 2005 with something new to him. ....been successfully using the regular expression validators from the toolbox, but now I have need to do...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.