Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2007

Tip: Looking for answers? Try searching our database.

Pattern Matcher Again

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
konrad Krupa - 07 Sep 2007 19:56 GMT
This message is a continuation of my previous post "Pattern Match"

Doug - Thank  you for your help.

Doug Semler was able to solve my problem to some point but I still need some
help.

Doug's pattern is going to make sure that I don't get match of ddd dd
embeded in number. For example

1234 5678

I wanto match ddd dd but not if it has numbers directly to the left or right
of it.

Now I still need to be able to match ddd dd in text that consists of only
"123 45"; no spaces in front or at the end.

Thanks in advance.

-----------------
Original posts

Thank you for the tip.

The pattern you suggested fixes problem 12345 6789

but I still need to get match on string that has only 123 45

Is there any way to get them in one pattern?

Konrad.
"Doug Semler" <dougsemler@gmail.com> wrote in message
news:1189179369.874384.278270@r29g2000hsg.googlegroups.com...
> On Sep 7, 11:33 am, Doug Semler <dougsem...@gmail.com> wrote:
>> On Sep 7, 11:16 am, "konrad Krupa" <kon...@commandtech.com> wrote:
>>
>> > I'm not expert in Pattern Matching and it would take me a while to come
>> > up
>> > with the syntax for what I'm trying to do.
>> > I hope there are some experts that can help me.
>>
>> > I'm trying to match /d/d/d/s/d/d in any text.
>>
>> > There could be spaces in front or after the pattern (the nnn nn could
>> > be
>> > without spaces also) but it shouldn't pick it up in case like this
>>
>> > 1234 56768
>>
>> > above pattern would give me 234 56.
>>
>> > If I do this /s/d/d/d/s/d/d/s
>> > then I have to have spaces in  front and after it, which is not the
>> > case.
>>
>> > Konrad.
>>
>> howbout something like
>> [^\d]\d{3}\s+\d{2}
>>
>> (Non digit followed by 3 digits followed by one or more whitespace
>> followed by 2 digits)
>
> P.S. If you want to get only the digit match, you'll want to capture
> it by sticking it into a catpuring group, like this:
>
> [^\d](\d{3}\s+\d{2})

------------------------------------------------

I'm pasting my initial question.
Rak - 07 Sep 2007 22:52 GMT
use ^  and $ for matching start and end like:

Regex rx = new Regex(@"^\d\d\d\s\d\d$");

HTH,
Rakesh

> This message is a continuation of my previous post "Pattern Match"
>
[quoted text clipped - 66 lines]
>
> I'm pasting my initial question.
Doug Semler - 08 Sep 2007 01:27 GMT
> use ^  and $ for matching start and end like:
>
> Regex rx = new Regex(@"^\d\d\d\s\d\d$");

That won't quite work if the regex settings are wrong.

If you want to NOT match if there are other digits on EITHER side (which is
finally the right problem domain):

[^\d](\d{3}\s+\d{2})[^\d]

This matches:
  Any 3 digit sequence followed by any number of spaces followed by a 2
digit sequence as long as the sequence doesn't have a digit on either side
of it.
 It also places the sequence into capturing group #1 via the parenthesis.

If you want to match exactly 1 space, remove the '+' character.
If you want to match 0 or more spaces between the digits make the '+' a '*'
If you want to match an exact number of spaces between the digit sequences,
replace the '+' with a "{n}" where n = exact number
If you want to match a number of spaces from n to m replace the '+' with
"{n,m}" where n is the minimum number of spaces and m is the maximum.

There is a tool out there called Expresso (at least there was a couple years
ago) that lets you play around with regular expressions.  I'd try to get a
hold of that if you are going to do more complicated expressions...

(Note, you really should have kept this in the original thread....)

Signature

Doug Semler, MCPD
a.a. #705, BAAWA.  EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?

konrad Krupa - 09 Sep 2007 03:27 GMT
Thanks again for your reply.

You are right, I should have kept it under the original thread.

I just responded to your last reply in previous thread with better
explanation  of my problem.

Thanks again.

Konrad

>> use ^  and $ for matching start and end like:
>>
[quoted text clipped - 26 lines]
>
> (Note, you really should have kept this in the original thread....)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.