473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another question about regex (not understanding)

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

"maggie" <ma****@discuss ions.microsoft. comwrote in message
news:5E******** *************** ***********@mic rosoft.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
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

"maggie" <ma****@discuss ions.microsoft. comwrote in message
news:8E******** *************** ***********@mic rosoft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
794
by: chris | last post by:
i can see the power of regular expressions but am having a bit of a battle getting my head around them. can anyone recommend some BASIC - tutorials for using regex something like th idots guide :) or even total idiots guide :) somewhere that has some simple examples would be good toooo
5
3819
by: Andrew Dixon | last post by:
Hi Everyone. Ok I have a problem getting the following regex to work in Java. <script*>(.|\r|\n)+?</script> It works fine in EditPad Pro but in Java it causes the following error message when ran:- 'Exception in thread "main" java.lang.StackOverflowError'
2
1505
by: John Perks and Sarah Mount | last post by:
I have to split some identifiers that are casedLikeThis into their component words. In this instance I can safely use to represent uppercase, but what pattern should I use if I wanted it to work more generally? I can envisage walking the string testing the unicodedata.category of each char, but is there a regex'y way to denote "uppercase"? Thanks John
2
1864
by: Daniel Billingsley | last post by:
First, if MSFT is listening I'll say IMO the MSDN material is sorely lacking in this area... it's just a whole bunch of information thrown at you and you're left to yourself as to organizing it in your head. Typical learning starts with basics and progresses through increasingly complex information - I think given the inherent confusion-inducing ability of regex that kind of documentation would be very valuable. But anyway, I'm trying...
6
396
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
7
2609
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b) every occurrence of characters "p", "q", "r", "s" with "y". Right now, I do it as follows:
20
8092
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex matches are called within a loop (like if or for). E.g. for(int i = 0; i < 10; i++) { Regex r = new Regex();
17
1645
by: steve | last post by:
here's the deal...cvs, tick encapsulted data. trying to use regex's to validate records. here's an example row: 'AD,'BF','132465','06/09/2004','','BNSF','A','TYPE','1278','','BR','2999','' ,'LX','','01','09','1','','','','','','','','','CUSTOM JOB CODE TEST' record type is in the 8th column ('1278'). using regex b/c there are a miriad of types that cause other data w/n the record (or related records) to be in/valid. i'm having problems...
16
2244
by: Mark Chambers | last post by:
Hi there, I'm seeking opinions on the use of regular expression searching. Is there general consensus on whether it's now a best practice to rely on this rather than rolling your own (string) pattern search functions. Where performance is an issue you can alway write your own specialized routine of course. However, for the occasional pattern search where performance isn't an issue, would most seasoned .NET developers rely on "Regex" and...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.