Pattern Matcher Again

K

konrad Krupa

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 said:
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.

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.
 
G

Guest

use ^ and $ for matching start and end like:

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

HTH,
Rakesh

konrad Krupa said:
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 said:
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.
 
D

Doug Semler

Rak said:
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....)

--
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?
 
K

konrad Krupa

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


Doug Semler said:
Rak said:
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....)

--
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top