\r\n\r\n
Regular Expressions Topics include: System.Text.RegularExpressions classes, and .NET regular expression syntax.

Go Back  Xtreme .NET Talk > .NET > Regular Expressions > searching for one or two numbers fails??


\r\n \r\n \r\n \r\n
 
 
Thread Tools Display Modes
\r\n \r\n
\r\n
\r\n \r\n hi,
\r\n
\r\nI\'ve a problem with a regular expression..
\r\nI\'ll use it, to..
\r\n match a bank account line, so accept the complete line
\r\n and filter two 6-digit-numbers out of the string to put it in reference 1 and 2
\r\n (or only one, thats the problem)
\r\n (for later use with coldfusions REreplace function ..
\r\n :select all text and replace it with the numbers, found in the text, separated by kommas )
\r\n
\r\nheres the regEx:
\r\n^(?:.*?)(\\d{6,6})(?:-\\d{2,2}|)(?:.*?)(?:(\\d{6,6})(?:-\\d{2,2}|))?
\r\n
\r\nnow, you can see the problem in the result of example 2 (using regexTester).
\r\nwhere is the second number,
\r\nthe regex doesnt find it, but why does it succed in searching in example 3?
\r\n
\r\nthank you
\r\n
\r\nexample rows:
\r\n1: hans meier rechnung nr.04-123456-04 fa any
\r\n2: hans meier rechnung nr.04-123456 777777-04 fa any
\r\n3: hans meier rechnung nr.04-123456777777-04 fa any
\r\n
\r\nresults:
\r\n1: ok, data in ref. 1
\r\n2: not ok (data in ref.1 ok, but 2 is empty)
\r\n3: ok data in ref. 1+2 (removed whitespace between the numbers)\r\n
\r\n
\r\n \r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; pd[434621] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n \r\n\r\n
\r\n
\r\n  \r\n #2  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 01-12-2005, 11:29 AM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
Richard Crist\'s Avatar\r\n\r\n
\r\n \r\n Richard Crist\r\n Richard Crist is offline\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n \r\n
\r\n
Quote:
\r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n Originally Posted by Richard Crist\r\n \r\n
\r\n
1) You would like to find only rows with two 6-digit numbers?
\r\n2) And then pull out those two 6-digit numbers for use later?
\r\n3) So only row 2 above is a good row, and from that row you want the numbers 123456 and 777777 for use later?
\r\n \r\n
\r\n
Since the poster hasn\'t replied and this thread seems popular, I shall post the answer.
\r\n
\r\n\\D*(\\d{6})\\D+(\\d{6})\\D*
\r\n
\r\nThis says find:
\r\nzero or more non-digit characters
\r\nfollowed by a 6 digit number
\r\nfollowed by 1 or more non-digit characters
\r\nfollowed by zero or more non-digit characters
\r\n
\r\nThe numbers you want will be in groups 1 and 2, represented by the first and second parentheses.
\r\n
\r\nInformation can be found here.\r\n
\r\n
\r\n \r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n
\r\n __________________
\r\n nothing unreal exists
\r\n.NET Framework Homepage ~ Visual C# Spec ~ C++/CLI Spec ~ Visual Basic .NET Spec\r\n
\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n
\r\n \r\n
\r\n
\r\n
\r\n\r\n\r\n\r\n'; pd[437246] = '\r\n\r\n \r\n\r\n
\r\n
\r\n
\r\n\r\n
\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n \r\n
\r\n
\r\n  \r\n #4  \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n
\r\n \r\n Old\r\n \r\n 02-16-2005, 07:55 AM\r\n \r\n \r\n \r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n
Richard Crist\'s Avatar\r\n\r\n
\r\n \r\n Richard Crist\r\n Richard Crist is offline\r\n\r\n\r\n
Prev Previous Post   Next Post Next
  #1  
Old 09-13-2004, 09:34 PM
federente federente is offline
Newcomer
 
Join Date: Sep 2004
Posts: 2
federente is on a distinguished road
Default searching for one or two numbers fails??

hi,

I've a problem with a regular expression..
I'll use it, to..
match a bank account line, so accept the complete line
and filter two 6-digit-numbers out of the string to put it in reference 1 and 2
(or only one, thats the problem)
(for later use with coldfusions REreplace function ..
:select all text and replace it with the numbers, found in the text, separated by kommas )

heres the regEx:
^(?:.*?)(\d{6,6})(?:-\d{2,2}|)(?:.*?)(?:(\d{6,6})(?:-\d{2,2}|))?

now, you can see the problem in the result of example 2 (using regexTester).
where is the second number,
the regex doesnt find it, but why does it succed in searching in example 3?

thank you

example rows:
1: hans meier rechnung nr.04-123456-04 fa any
2: hans meier rechnung nr.04-123456 777777-04 fa any
3: hans meier rechnung nr.04-123456777777-04 fa any

results:
1: ok, data in ref. 1
2: not ok (data in ref.1 ok, but 2 is empty)
3: ok data in ref. 1+2 (removed whitespace between the numbers)
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql query fails inter Database / XML / Reporting 4 09-23-2005 03:34 AM
Updating datasource from dataset fails paulhudson Database / XML / Reporting 0 03-01-2005 05:49 AM
My Application fails in win2000 EFileTahi-A General 3 12-06-2004 08:08 PM
application deployment fails on Pocket PC pavel47 Deployment 0 07-19-2004 11:52 AM
importrow --> update fails Mischamel Database / XML / Reporting 10 03-10-2004 06:58 AM

Advertisement:

Powered by liquidweb