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