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

Pattern Matcher Again

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" <do********@gmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
On Sep 7, 11:33 am, Doug Semler <dougsem...@gmail.comwrote:
>On Sep 7, 11:16 am, "konrad Krupa" <kon...@commandtech.comwrote:


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.

Sep 7 '07 #1
3 1616
use ^ and $ for matching start and end like:

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

HTH,
Rakesh

"konrad Krupa" wrote:
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" <do********@gmail.comwrote in message
news:11**********************@r29g2000hsg.googlegr oups.com...
On Sep 7, 11:33 am, Doug Semler <dougsem...@gmail.comwrote:
On Sep 7, 11:16 am, "konrad Krupa" <kon...@commandtech.comwrote:

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.

Sep 7 '07 #2
"Rak" <Ra*@discussions.microsoft.comwrote in message
news:94**********************************@microsof t.com...
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?

Sep 8 '07 #3
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" <do********@gmail.comwrote in message
news:OR**************@TK2MSFTNGP04.phx.gbl...
"Rak" <Ra*@discussions.microsoft.comwrote in message
news:94**********************************@microsof t.com...
>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?

Sep 9 '07 #4

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

Similar topics

1
by: Dean A. Hoover | last post by:
I've got a 4 line message that looks like this: Encountered "<EOF>" at line 1, column 7. Was expecting one of: "=" ... "]]" ... and want to get the line and column numbers from it. This is...
0
by: Revenge | last post by:
Hi all, I have a problem with the Pattern.matcher method. When I try to find a string with a regular expression, sometimes it throws an error as: "Illegal repetition near index 18" or "Unclosed...
4
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
2
by: Ole Nielsby | last post by:
First, bear with my xpost. This goes to comp.lang.c++ comp.lang.functional with follow-up to comp.lang.c++ - I want to discuss an aspect of using C++ to implement a functional language, and...
1
by: JosAH | last post by:
Greetings, this week we let go of all that algebraic stuff and concentrate a bit more on what object oriented programming is all about. Java claims to support OO, so why not use it? In this...
19
by: konrad Krupa | last post by:
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...
5
by: basm101 | last post by:
Hi, I am trying to match a string like this: test (AB12 A) including the brackets. So far, I have this code: Pattern p = Pattern.compile("+/s+\\({2}{2}/s+{1}\\)"); Matcher m =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.