Pattern Match

K

konrad Krupa

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

Doug Semler

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)
 
D

Doug Semler

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})
 
K

konrad Krupa

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})
 
A

Arnshea

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?




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})- Hide quoted text -

- Show quoted text -

\d{3}\s+\d{2} should do the trick. There should be 2 matches each
with 1 captured group in each match. For example

given input "123 45" matches[0].Groups[0].Captures[0].Value will be
"123 45"
given input "123 45 abcd 12345 6789and then some" then there will be 2
matches:
- matches[0].Groups[0].Captures[0].Value = "123 45"
- matches[1].Groups[0].Captures[0].Value = "345 67"

Since there are no parenthesis only the default captured sub-
expression (which is the entire match) matches.

Here's a demo program I use to test out regular expressions. Compile
it then call it passing a a regular expression (surround by double
quotes if the expression has spaces) and a string to test (again
double quote it if it contains spaces).

static void Main(string[] args)
{
string pat = args[0];
string text = args[1];

Console.WriteLine("pattern: {0}\ninput: {1}", pat, text);

Regex r = new Regex(pat);
MatchCollection matches = r.Matches(text);

Console.WriteLine("number of matches: {0}", matches.Count);
if ( matches.Count > 0 )
{
for (int i=0; i < matches.Count; i++)
{
Console.WriteLine("captured groups in match[{0}]: {1}", i,
matches.Groups.Count);
for (int j=0; j < matches.Groups.Count; j++)
{
Console.WriteLine("substrings captured by group[{0}]: {1}", j,
matches.Groups[j].Captures.Count);
for (int k=0; k < matches.Groups[j].Captures.Count; k++)
{
Console.WriteLine("captured substring[{0}]={1}", k,
matches.Groups[j].Captures[k].Value);
}
}
}
}
 
D

Doug Semler

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?




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

Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?

I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.
 
D

Doug Semler

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?
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})- Hide quoted text -
- Show quoted text -

\d{3}\s+\d{2} should do the trick. There should be 2 matches each
with 1 captured group in each match. For example


Only problem with that pattern is that he said he doesn't want to
match if there is a digit in front of the 3 digit space 2 digit
pattern

He hasn't defined his pattern that he wants to match well enough.
 
K

konrad Krupa

Thanks for your replies.

I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but not a
number.
After the last digit there can be(doesn't have to) a space but not a digit.


123 45

This sequence of numbers can be embedded in sentence or the entire sentence
can be just the sequence "123 45"

What is invalid is this:

12345 67890

I don't want 345 67 to be matched.

The numbers can be preceeded or followed by space for example:

" 123 45 "
" 123 45"
"123 45 "

This is valid.

I hope this helps.

Konrad.
Doug Semler said:
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?




On Sep 7, 11:16 am, "konrad Krupa" <[email protected]> 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.

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

Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?

I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.
 
A

Arnshea

Thanks for your replies.

I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but not a
number.
After the last digit there can be(doesn't have to) a space but not a digit.

123 45

This sequence of numbers can be embedded in sentence or the entire sentence
can be just the sequence "123 45"

What is invalid is this:

12345 67890

I don't want 345 67 to be matched.

The numbers can be preceeded or followed by space for example:

" 123 45 "
" 123 45"
"123 45 "

This is valid.

I hope this helps.




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?

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
Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.- Hide quoted text -

- Show quoted text -

Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the zero-
width negative lookbehind assertion (basically a way of saying
"anything not to the left of a number").
 
A

Arnshea

Thanks for your replies.
I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but not a
number.
After the last digit there can be(doesn't have to) a space but not a digit.
This sequence of numbers can be embedded in sentence or the entire sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890
I don't want 345 67 to be matched.
The numbers can be preceeded or followed by space for example:
" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.
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?

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
Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.- Hide quoted text -
- Show quoted text -

Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the zero-
width negative lookbehind assertion (basically a way of saying
"anything not to the left of a number").- Hide quoted text -

- Show quoted text -

err, sorry the zero-width negative lookbehind assertion is basically a
way of saying anything not to the RIGHT of a number.
 
K

konrad Krupa

So,
Do you have any idea how to do it?

Konrad
Arnshea said:
Thanks for your replies.
I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but
not a
number.
After the last digit there can be(doesn't have to) a space but not a
digit.
This sequence of numbers can be embedded in sentence or the entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890
I don't want 345 67 to be matched.
The numbers can be preceeded or followed by space for example:
" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.
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?
On Sep 7, 11:16 am, "konrad Krupa" <[email protected]>
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.

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

Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.- Hide quoted text -
- Show quoted text -

Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the zero-
width negative lookbehind assertion (basically a way of saying
"anything not to the left of a number").- Hide quoted text -

- Show quoted text -

err, sorry the zero-width negative lookbehind assertion is basically a
way of saying anything not to the RIGHT of a number.
 
A

Arnshea

So,
Do you have any idea how to do it?




Thanks for your replies.
I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but
not a
number.
After the last digit there can be(doesn't have to) a space but not a
digit.
123 45
This sequence of numbers can be embedded in sentence or the entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890
I don't want 345 67 to be matched.
The numbers can be preceeded or followed by space for example:
" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.

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?

On Sep 7, 11:16 am, "konrad Krupa" <[email protected]>
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
Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.- Hide quoted text -
- Show quoted text -
Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the zero-
width negative lookbehind assertion (basically a way of saying
"anything not to the left of a number").- Hide quoted text -
- Show quoted text -
err, sorry the zero-width negative lookbehind assertion is basically a
way of saying anything not to the RIGHT of a number.- Hide quoted text -

- Show quoted text -

I believe the pattern you want is:

(?<!\d)\d{3}\s\d{2}
 
D

Doug Semler

So,
Do you have any idea how to do it?
Thanks for your replies.
I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but
not a
number.
After the last digit there can be(doesn't have to) a space but not a
digit.
123 45
This sequence of numbers can be embedded in sentence or the entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890
I don't want 345 67 to be matched.
The numbers can be preceeded or followed by space for example:
" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.

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?

On Sep 7, 11:16 am, "konrad Krupa" <[email protected]>
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
Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.- Hide quoted text -
- Show quoted text -
Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the zero-
width negative lookbehind assertion (basically a way of saying
"anything not to the left of a number").- Hide quoted text -
- Show quoted text -
err, sorry the zero-width negative lookbehind assertion is basically a
way of saying anything not to the RIGHT of a number.- Hide quoted text -
- Show quoted text -

I believe the pattern you want is:

(?<!\d)\d{3}\s\d{2}

Unfortunately that still matches the expression 3digit space 2digit
pattern with digits following the pattern. Which he said he didn't
want. You need to match if prefix is absent as well, which would be

(?<!\d)\d{3}\s\d{2}(?!\d)


which says: Match any 3 digits followed by a space followed by 2
digits that is not on either side of a digit.
 
A

Arnshea

So,
Do you have any idea how to do it?

Thanks for your replies.
I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a space but
not a
number.
After the last digit there can be(doesn't have to) a space but not a
digit.
123 45
This sequence of numbers can be embedded in sentence or the entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890
I don't want 345 67 to be matched.
The numbers can be preceeded or followed by space for example:
" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.

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?

On Sep 7, 11:16 am, "konrad Krupa" <[email protected]>
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
Dude, define your problem. What, EXACTLY do you need to match? What
are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or behind.
You need to define your problem better. The pattern I gave you will
find 123 45.- Hide quoted text -
- Show quoted text -
Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the zero-
width negative lookbehind assertion (basically a way of saying
"anything not to the left of a number").- Hide quoted text -
- Show quoted text -
err, sorry the zero-width negative lookbehind assertion is basically a
way of saying anything not to the RIGHT of a number.- Hide quoted text -
- Show quoted text -
I believe the pattern you want is:
(?<!\d)\d{3}\s\d{2}

Unfortunately that still matches the expression 3digit space 2digit
pattern with digits following the pattern. Which he said he didn't
want. You need to match if prefix is absent as well, which would be

(?<!\d)\d{3}\s\d{2}(?!\d)

which says: Match any 3 digits followed by a space followed by 2
digits that is not on either side of a digit.- Hide quoted text -

- Show quoted text -

doh! You're right - you need the trailing zero-width negative
lookahead. Pretty cool imho - .Net regular expressions did what I
wouldn't have thought possible; improve on PERL5 regexps!
 
J

Jesse Houwing

Hello Arnshea,
So,
Do you have any idea how to do it?



On Sep 8, 10:24 pm, "konrad Krupa" <[email protected]>
wrote:

Thanks for your replies.

I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a
space but
not a
number.
After the last digit there can be(doesn't have to) a space but
not a
digit.
123 45

This sequence of numbers can be embedded in sentence or the
entire
sentence
can be just the sequence "123 45"
What is invalid is this:

12345 67890

I don't want 345 67 to be matched.

The numbers can be preceeded or followed by space for example:

" 123 45 "
" 123 45"
"123 45 "
This is valid.

I hope this helps.



On Sep 7, 12:58 pm, "konrad Krupa" <[email protected]>
wrote:

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?




On Sep 7, 11:16 am, "konrad Krupa" <[email protected]>
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

Dude, define your problem. What, EXACTLY do you need to match?
What are you trying to find?

I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or
behind. You need to define your problem better. The pattern I
gave you will find 123 45.- Hide quoted text -

- Show quoted text -

Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the
zero- width negative lookbehind assertion (basically a way of
saying "anything not to the left of a number").- Hide quoted text
-

- Show quoted text -

err, sorry the zero-width negative lookbehind assertion is
basically a way of saying anything not to the RIGHT of a number.-
Hide quoted text -

- Show quoted text -

I believe the pattern you want is:

(?<!\d)\d{3}\s\d{2}
Unfortunately that still matches the expression 3digit space 2digit
pattern with digits following the pattern. Which he said he didn't
want. You need to match if prefix is absent as well, which would be

(?<!\d)\d{3}\s\d{2}(?!\d)

which says: Match any 3 digits followed by a space followed by 2
digits that is not on either side of a digit.- Hide quoted text -

- Show quoted text -
doh! You're right - you need the trailing zero-width negative
lookahead. Pretty cool imho - .Net regular expressions did what I
wouldn't have thought possible; improve on PERL5 regexps!

That also works in PERL5 regex. It would've been even easier to use the \b
boundy:

\b\d{3}\s\d{2}\b would've had the same result. That even works in much older
PERL versions.

Jesse
 
A

Arnshea

Hello Arnshea,




So,
Do you have any idea how to do it?

On Sep 8, 10:24 pm, "konrad Krupa" <[email protected]>
wrote:
Thanks for your replies.
I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a
space but
not a
number.
After the last digit there can be(doesn't have to) a space but
not a
digit.
123 45
This sequence of numbers can be embedded in sentence or the
entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890
I don't want 345 67 to be matched.
The numbers can be preceeded or followed by space for example:
" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.

On Sep 7, 12:58 pm, "konrad Krupa" <[email protected]>
wrote:
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?

On Sep 7, 11:16 am, "konrad Krupa" <[email protected]>
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
Dude, define your problem. What, EXACTLY do you need to match?
What are you trying to find?
I gave you a pattern that matched 3 digits + one or more spaces
followed by two digits. Regardless of what came in front or
behind. You need to define your problem better. The pattern I
gave you will find 123 45.- Hide quoted text -
- Show quoted text -
Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the
zero- width negative lookbehind assertion (basically a way of
saying "anything not to the left of a number").- Hide quoted text
-
- Show quoted text -
err, sorry the zero-width negative lookbehind assertion is
basically a way of saying anything not to the RIGHT of a number.-
Hide quoted text -
- Show quoted text -
I believe the pattern you want is:
(?<!\d)\d{3}\s\d{2}
Unfortunately that still matches the expression 3digit space 2digit
pattern with digits following the pattern. Which he said he didn't
want. You need to match if prefix is absent as well, which would be
(?<!\d)\d{3}\s\d{2}(?!\d)
which says: Match any 3 digits followed by a space followed by 2
digits that is not on either side of a digit.- Hide quoted text -
- Show quoted text -
doh! You're right - you need the trailing zero-width negative
lookahead. Pretty cool imho - .Net regular expressions did what I
wouldn't have thought possible; improve on PERL5 regexps!

That also works in PERL5 regex. It would've been even easier to use the \b
boundy:

\b\d{3}\s\d{2}\b would've had the same result. That even works in much older
PERL versions.

Jesse
--
Jesse Houwing
jesse.houwing at sogeti.nl- Hide quoted text -

- Show quoted text -

I don't think that would catch "123 45a".
 
D

Doug Semler

Arnshea said:
I don't think that would catch "123 45a".


It doesn't. And he said that spaces in front or behind are "optional" but
cannot be a digit. Which tells me that "a123 45" is an acceptable match ->
result "123 45"

Unless of course the OP changes the requirements again <g>

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

Jesse Houwing

Hello Arnshea,
Hello Arnshea,
So,
Do you have any idea how to do it?


On Sep 8, 10:24 pm, "konrad Krupa" <[email protected]>
wrote:

Thanks for your replies.

I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a
space but
not a
number.
After the last digit there can be(doesn't have to) a space but
not a
digit.
123 45
This sequence of numbers can be embedded in sentence or the
entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890

I don't want 345 67 to be matched.

The numbers can be preceeded or followed by space for example:

" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.



On Sep 7, 12:58 pm, "konrad Krupa" <[email protected]>
wrote:

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?


.

On Sep 7, 11:33 am, Doug Semler <[email protected]>
wrote:

On Sep 7, 11:16 am, "konrad Krupa"

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
Dude, define your problem. What, EXACTLY do you need to
match? What are you trying to find?

I gave you a pattern that matched 3 digits + one or more
spaces followed by two digits. Regardless of what came in
front or behind. You need to define your problem better. The
pattern I gave you will find 123 45.- Hide quoted text -

- Show quoted text -

Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the
zero- width negative lookbehind assertion (basically a way of
saying "anything not to the left of a number").- Hide quoted
text -

- Show quoted text -

err, sorry the zero-width negative lookbehind assertion is
basically a way of saying anything not to the RIGHT of a
number.- Hide quoted text -

- Show quoted text -

I believe the pattern you want is:

(?<!\d)\d{3}\s\d{2}

Unfortunately that still matches the expression 3digit space 2digit
pattern with digits following the pattern. Which he said he didn't
want. You need to match if prefix is absent as well, which would
be

(?<!\d)\d{3}\s\d{2}(?!\d)

which says: Match any 3 digits followed by a space followed by 2
digits that is not on either side of a digit.- Hide quoted text -

- Show quoted text -

doh! You're right - you need the trailing zero-width negative
lookahead. Pretty cool imho - .Net regular expressions did what I
wouldn't have thought possible; improve on PERL5 regexps!
That also works in PERL5 regex. It would've been even easier to use
the \b boundy:

\b\d{3}\s\d{2}\b would've had the same result. That even works in
much older PERL versions.

Jesse
I don't think that would catch "123 45a".

You're completely correct. The original problem had shrunk (read slowly deteriorated)
in the message I replied to.
 
K

konrad Krupa

Hello again.


Thank you for the great discussion and all the postings.

I believe that the pattern Doug sent works.

Once again thanks for the effort.


Jesse Houwing said:
Hello Arnshea,
Hello Arnshea,




So,
Do you have any idea how to do it?


On Sep 8, 10:24 pm, "konrad Krupa" <[email protected]>
wrote:

Thanks for your replies.

I have to find 3 digits followed by space and then 2 digits.
In front of the first digit there can be( doesn't have to) a
space but
not a
number.
After the last digit there can be(doesn't have to) a space but
not a
digit.
123 45
This sequence of numbers can be embedded in sentence or the
entire
sentence
can be just the sequence "123 45"
What is invalid is this:
12345 67890

I don't want 345 67 to be matched.

The numbers can be preceeded or followed by space for example:

" 123 45 "
" 123 45"
"123 45 "
This is valid.
I hope this helps.



On Sep 7, 12:58 pm, "konrad Krupa" <[email protected]>
wrote:

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?


.

On Sep 7, 11:33 am, Doug Semler <[email protected]>
wrote:

On Sep 7, 11:16 am, "konrad Krupa"

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
Dude, define your problem. What, EXACTLY do you need to
match? What are you trying to find?

I gave you a pattern that matched 3 digits + one or more
spaces followed by two digits. Regardless of what came in
front or behind. You need to define your problem better. The
pattern I gave you will find 123 45.- Hide quoted text -

- Show quoted text -

Ahh, ok. Try (?<!\d)\d{3}\s\d{2} as your pattern. Needed the
zero- width negative lookbehind assertion (basically a way of
saying "anything not to the left of a number").- Hide quoted
text -

- Show quoted text -

err, sorry the zero-width negative lookbehind assertion is
basically a way of saying anything not to the RIGHT of a
number.- Hide quoted text -

- Show quoted text -

I believe the pattern you want is:

(?<!\d)\d{3}\s\d{2}

Unfortunately that still matches the expression 3digit space 2digit
pattern with digits following the pattern. Which he said he didn't
want. You need to match if prefix is absent as well, which would
be

(?<!\d)\d{3}\s\d{2}(?!\d)

which says: Match any 3 digits followed by a space followed by 2
digits that is not on either side of a digit.- Hide quoted text -

- Show quoted text -

doh! You're right - you need the trailing zero-width negative
lookahead. Pretty cool imho - .Net regular expressions did what I
wouldn't have thought possible; improve on PERL5 regexps!

That also works in PERL5 regex. It would've been even easier to use
the \b boundy:

\b\d{3}\s\d{2}\b would've had the same result. That even works in
much older PERL versions.

Jesse
I don't think that would catch "123 45a".

You're completely correct. The original problem had shrunk (read slowly
deteriorated) in the message I replied to.
 
D

Doug Semler

You're completely correct. The original problem had shrunk (read slowly
deteriorated) in the message I replied to.

This is what happens when an expression problem is not well defined in terms
of character classes <g>

It started as "I want to detect three digits followed by a space followed by
two digits"
Then we found out that there may or may not be a space on either side.
THEN we found out that we DON'T want to match when there is not a digit on
either side. But, we really don't know if letters are acceptable instead of
a space. <shrug>



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