By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,742 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,742 IT Pros & Developers. It's quick & easy.

Another question about regex (not understanding)

P: n/a
hi,

I've been working getting a file parsed out using Regex. There's something I
don't understand. When I define the pattern for my fields in my file, I am
telling regex to grab those fields ( strings and salary figures, numbers with
decimals) . Some of the fields contain commas, so that's why I'm using Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so , for
each field. I'm really stuck. Can somebody explain? I think that might help.
If my file is split on commas, then how do I tell Regex that? In the pattern?

thanks-
Expand|Select|Wrap|Line Numbers
  1. Dim objRE
  2. Dim i As Integer
  3. Dim pattern As String
  4. pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
  5. objRE = New Regex(pattern)
  6.  
  7. 'from 4guys  :
  8.  
  9. SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  10.  
Dec 12 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"maggie" <ma****@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
hi,

I've been working getting a file parsed out using Regex. There's something
I
don't understand. When I define the pattern for my fields in my file, I am
telling regex to grab those fields ( strings and salary figures, numbers
with
decimals) . Some of the fields contain commas, so that's why I'm using
Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so ,
for
each field. I'm really stuck. Can somebody explain? I think that might
help.
If my file is split on commas, then how do I tell Regex that? In the
pattern?

thanks-
Expand|Select|Wrap|Line Numbers
  1. Dim objRE
  2.        Dim i As Integer
  3.        Dim pattern As String
  4.        pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
  5.         objRE = New Regex(pattern)
  6. 'from 4guys  :
  7.        SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  8.  
Can you not use the CSV data provider to read the file. You can set up an
ODBC connection to the file and then read it in using the data classes
provided by dot.net.

I have used it in ASP.NET but should be the same. Create a BindingSource
and when you are asked to choose your data source select database , then MS
ODBC Data Source. You will have to create the ODBC source using the ODBC
Data Source Administrator. Basically you point to the file and use the
*.txt, *.csv driver. Once you have done that you can easily read the file
using the connection without all the worries you have right now.

Hope this helps
Lloyd Sheen

Dec 12 '07 #2

P: n/a
Why didn't I do this before? for some weird reason, I had to use regex. Dumb,
dumb,dumb. I can't tell you how much time I spent on it. I was close though.
Thanks so much Lloyd. You saved me! :):):)

"maggie" wrote:
hi,

I've been working getting a file parsed out using Regex. There's something I
don't understand. When I define the pattern for my fields in my file, I am
telling regex to grab those fields ( strings and salary figures, numbers with
decimals) . Some of the fields contain commas, so that's why I'm using Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so , for
each field. I'm really stuck. Can somebody explain? I think that might help.
If my file is split on commas, then how do I tell Regex that? In the pattern?

thanks-
Expand|Select|Wrap|Line Numbers
  1.  Dim objRE
  2.         Dim i As Integer
  3.         Dim pattern As String
  4.         pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
  5.          objRE = New Regex(pattern)
  6. 'from 4guys  :
  7.         SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  8.  
Dec 12 '07 #3

P: n/a

"maggie" <ma****@discussions.microsoft.comwrote in message
news:8E**********************************@microsof t.com...
Why didn't I do this before? for some weird reason, I had to use regex.
Dumb,
dumb,dumb. I can't tell you how much time I spent on it. I was close
though.
Thanks so much Lloyd. You saved me! :):):)

"maggie" wrote:
>hi,

I've been working getting a file parsed out using Regex. There's
something I
don't understand. When I define the pattern for my fields in my file, I
am
telling regex to grab those fields ( strings and salary figures, numbers
with
decimals) . Some of the fields contain commas, so that's why I'm using
Regex.
This is a comma-delimited file. I am not understanding the Split command.
Right now , my file is being split into 4 occurrences, not the 25 or so ,
for
each field. I'm really stuck. Can somebody explain? I think that might
help.
If my file is split on commas, then how do I tell Regex that? In the
pattern?

thanks-
Expand|Select|Wrap|Line Numbers
  1.  Dim objRE
  2.         Dim i As Integer
  3.         Dim pattern As String
  4.         pattern = " [a-z/.0-9]+([0-9,]{5}.[0-9]{2})" ' sort of works
  5.          objRE = New Regex(pattern)
  6. 'from 4guys  :
  7.         SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
Glad that helps. What I have found with all the classes provided in dot.net
there is very little need to re-invent the wheel.

LS

Dec 12 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.