473,626 Members | 3,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with regex?

hi,
I need some help with a reg. expression. I have a comma delimited file with
quotes. Not every field has quotes, only some. This is a sample of my file:
99,"01/01/2007","23,000", 1,34,"henry",13 2,"45.00"

I used some code from an article that I though would do what I needed, but
it splits my amount fields(76,000 into two different fields : 76, and 000...
Do I change my pattern ? I never used regex before and need some help. thank
you.
Expand|Select|Wrap|Line Numbers
  1. Dim re As Object = SplitAdv(sr.ReadToEnd)
  2.  
  3. Function SplitAdv(ByVal strInput)
  4. Dim objRE
  5. Dim pattern As String
  6. pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
  7. objRE = New Regex(pattern)
  8. ' .Replace replaces the comma that we will use with
  9. ' chr(8), the \b character which is extremely unlikely
  10. ' to appear in any string it then splits the line into
  11. ' an array based on the \b
  12. 'Console.WriteLine(objRE.ToString)
  13. SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  14.  
  15. End Function
  16.  

Dec 10 '07 #1
4 1261
Hi,
I think I found a better pattern, but I can't seem to get it defined
correctly in a string
I have this:
pattern = "((?:[^',]|(?:'(?:\\{2}|' |[^'])*?'))*)"

I would like to change the single quotes to double quotes, but it doesnt
like what I'm doing. I tried putting escape characters before the " like so:
\", but it does not like it. How in the world can I do this? I've spent about
2 hours on this alone and am stuck. Please advise. Thanks!

"maggie" wrote:
hi,
I need some help with a reg. expression. I have a comma delimited file with
quotes. Not every field has quotes, only some. This is a sample of my file:
99,"01/01/2007","23,000", 1,34,"henry",13 2,"45.00"

I used some code from an article that I though would do what I needed, but
it splits my amount fields(76,000 into two different fields : 76, and 000...
Do I change my pattern ? I never used regex before and need some help. thank
you.
Expand|Select|Wrap|Line Numbers
  1. Dim re As Object = SplitAdv(sr.ReadToEnd)
  2. Function SplitAdv(ByVal strInput)
  3.         Dim objRE
  4.         Dim pattern As String
  5.         pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
  6.         objRE = New Regex(pattern)
  7.         ' .Replace replaces the comma that we will use with
  8.         ' chr(8), the \b character which is extremely unlikely
  9.         ' to appear in any string it then splits the line into
  10.         ' an array based on the \b
  11.         'Console.WriteLine(objRE.ToString)
  12.         SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  13.     End Function
  14.  

Dec 10 '07 #2
You might find Expresso useful (http://www.ultrapico.com/).

Since I already have a headache from my own regex mystery today I did not
try to understand your pattern, and I have never used the Regex Split
method. But I did play around with your basic problem and came up with the
following pattern

((?<q>"?)[/,\w\d\.]+\k<q>,?)

which yields this result

99,
"01/01/2007",
"23,000",
1,34,
"henry",
132,
"45.00"

when fed your sample data. IF that's what you want, and IF you don't need
to use the Split method.

Good Luck, Bob
"maggie" <ma****@discuss ions.microsoft. comwrote in message
news:25******** *************** ***********@mic rosoft.com...
hi,
I need some help with a reg. expression. I have a comma delimited file
with
quotes. Not every field has quotes, only some. This is a sample of my
file:
99,"01/01/2007","23,000", 1,34,"henry",13 2,"45.00"

I used some code from an article that I though would do what I needed, but
it splits my amount fields(76,000 into two different fields : 76, and
000...
Do I change my pattern ? I never used regex before and need some help.
thank
you.
Expand|Select|Wrap|Line Numbers
  1. Dim re As Object = SplitAdv(sr.ReadToEnd)
  2. Function SplitAdv(ByVal strInput)
  3.        Dim objRE
  4.        Dim pattern As String
  5.        pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
  6.        objRE = New Regex(pattern)
  7.        ' .Replace replaces the comma that we will use with
  8.        ' chr(8), the \b character which is extremely unlikely
  9.        ' to appear in any string it then splits the line into
  10.        ' an array based on the \b
  11.        'Console.WriteLine(objRE.ToString)
  12.        SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  13.    End Function
  14.  


Dec 10 '07 #3
I ,too,have a big headache, but you helped. I'm going to try it. Thanks very
much.
"eBob.com" wrote:
You might find Expresso useful (http://www.ultrapico.com/).

Since I already have a headache from my own regex mystery today I did not
try to understand your pattern, and I have never used the Regex Split
method. But I did play around with your basic problem and came up with the
following pattern

((?<q>"?)[/,\w\d\.]+\k<q>,?)

which yields this result

99,
"01/01/2007",
"23,000",
1,34,
"henry",
132,
"45.00"

when fed your sample data. IF that's what you want, and IF you don't need
to use the Split method.

Good Luck, Bob
"maggie" <ma****@discuss ions.microsoft. comwrote in message
news:25******** *************** ***********@mic rosoft.com...
hi,
I need some help with a reg. expression. I have a comma delimited file
with
quotes. Not every field has quotes, only some. This is a sample of my
file:
99,"01/01/2007","23,000", 1,34,"henry",13 2,"45.00"

I used some code from an article that I though would do what I needed, but
it splits my amount fields(76,000 into two different fields : 76, and
000...
Do I change my pattern ? I never used regex before and need some help.
thank
you.
Expand|Select|Wrap|Line Numbers
  1.  Dim re As Object = SplitAdv(sr.ReadToEnd)
  2.  
  3.  Function SplitAdv(ByVal strInput)
  4.         Dim objRE
  5.         Dim pattern As String
  6.         pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
  7.         objRE = New Regex(pattern)
  8.         ' .Replace replaces the comma that we will use with
  9.         ' chr(8), the \b character which is extremely unlikely
  10.         ' to appear in any string it then splits the line into
  11.         ' an array based on the \b
  12.         'Console.WriteLine(objRE.ToString)
  13.         SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  14.  
  15.     End Function
  16.  


Dec 10 '07 #4
eBob,

The dollar amounts came out on their own, but I still have some all strung
together with commas, which is better than what I had. I'll see if i can
separate them. Thanks again.

"eBob.com" wrote:
You might find Expresso useful (http://www.ultrapico.com/).

Since I already have a headache from my own regex mystery today I did not
try to understand your pattern, and I have never used the Regex Split
method. But I did play around with your basic problem and came up with the
following pattern

((?<q>"?)[/,\w\d\.]+\k<q>,?)

which yields this result

99,
"01/01/2007",
"23,000",
1,34,
"henry",
132,
"45.00"

when fed your sample data. IF that's what you want, and IF you don't need
to use the Split method.

Good Luck, Bob
"maggie" <ma****@discuss ions.microsoft. comwrote in message
news:25******** *************** ***********@mic rosoft.com...
hi,
I need some help with a reg. expression. I have a comma delimited file
with
quotes. Not every field has quotes, only some. This is a sample of my
file:
99,"01/01/2007","23,000", 1,34,"henry",13 2,"45.00"

I used some code from an article that I though would do what I needed, but
it splits my amount fields(76,000 into two different fields : 76, and
000...
Do I change my pattern ? I never used regex before and need some help.
thank
you.
Expand|Select|Wrap|Line Numbers
  1.  Dim re As Object = SplitAdv(sr.ReadToEnd)
  2.  
  3.  Function SplitAdv(ByVal strInput)
  4.         Dim objRE
  5.         Dim pattern As String
  6.         pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
  7.         objRE = New Regex(pattern)
  8.         ' .Replace replaces the comma that we will use with
  9.         ' chr(8), the \b character which is extremely unlikely
  10.         ' to appear in any string it then splits the line into
  11.         ' an array based on the \b
  12.         'Console.WriteLine(objRE.ToString)
  13.         SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
  14.  
  15.     End Function
  16.  


Dec 10 '07 #5

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

Similar topics

6
2047
by: Tony C | last post by:
I'm writing a python program which uses regular expressions, but I'm totally new to regexps. I've got Kuchling's "Regexp HOWTO", "Mastering Regular Expresions" by Oreilly, and have access to online stuff too. But I would like to find a mailing list or newsgroup where I can ask questions about regexps (when things don't work), not specifically dealing with Python. When I have Python-regexp questions, I'll post them here of course.
8
5576
by: Bibe | last post by:
I've been trying to get this going for awhile now, and need help. I've done a regex object, and when I use IsMatch, it's behavior is quite weird. I am trying to use Regex to make sure that a variable is only alphanumeric (no strange characters). Here's the code: Regex regExp = new Regex("*");
4
1511
by: H | last post by:
This is kind of an followup on oneof my previous questions, and it has with RegEx to do. I have a string containing of several words. What would a good regex expression looklike to get one match on every word ? For example : String myString =" This is the string that stupid H can't split up"; // A good RegEx needed here .. So the result would look something like this ;
6
4787
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search string. It's actually the input string into a Microsoft Index Server search. The string will consist of words, perhaps enclosed in quotes or parentheses. I'd like to use Regex to pull out the words, or the phrases if the words are enclosed in quotes....
4
3139
by: henrik | last post by:
Hi I have a regex question. I want to find all content of a <td class="someclass"> tag. This means the expression should include all other tags included between <td class="someclass"> and </td>. Please help Regards
9
2079
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat lot of times here.... Requirement: ------------------- I want to get the value of "href" i.e "city1.html" by searching "city1" between the <a</atag. Please note that "city1" can repeat lot of
2
2362
by: Alex Maghen | last post by:
This is a bit of an abuse of this group. Just a nit, but I'm hoping someone really good with Regular Expressions can help me out here. I need to write a regular expression that will do the following: Search a whole blob of text (including newlines and everything). Find any text enclosed in brackets (), and replace it with a string I provide and then concatenate the text that had been enclosed in the brakets, without the brakets.
3
4871
by: =?Utf-8?B?TmF2ZWVu?= | last post by:
Not sure if this is the right forum for this question but couldn'd find another newsgroup. I am new to Regular expressions and would like help in deciding which pattern allows me to split a string into sets of words based on capital letter. For e.g. if i have a string "FirstnameLastname" I would like the result to return me Firstname and Lastname. The other conditions of the input string are 1) If whitespace exists, do not return a...
10
1566
by: supercrossking | last post by:
I am trying to the values of string of text in the sample before. The ds are for digits and s is for string and string of text is for a string with more than one or two values. I am trying to use regex and the .groups method. Please help. d|d|d|string of text 1||s|s|||dd.dd|ss|string of text 2||||||||||||||||||||||||||string of text 2 I only want string of text1
0
1621
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with an '@'in the filename on the assumption it's already in the correct format. Uncomment the os.rename line
0
8269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8642
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...
1
8368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5576
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
4094
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...
1
2630
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
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.