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

Home Posts Topics Members FAQ

Regular expression problem, help please!

Hi

I need to write one regex to read all the fields from the following lines /
file format
line 1 - some_alphanumer ic,some_alphanu meric,"somethin g,
something",numb ers_hyphenatedO Rnot
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not

At first I thought this one will do
"[^"\r\n]*",|[A-Za-z0-9 ]*,|[0-9]*\-[0-9]*

but I am getting the delimiters such as the trailing comma and the
double-quote along with the fields !!

Can this be modified to get the fields only, or at least to get rid of the
trailing comma?

TIA
--

Nov 17 '05 #1
3 1448
> line 1 - some_alphanumer ic,

[A-Za-z0-9 ]*,

some_alphanumer ic,
[A-Za-z0-9 ]*,

"something, something",
"[~"]*",

numbers_hyphena tedORnot
[0-9-]*

All together: [A-Za-z0-9 ]*,[A-Za-z0-9 ]*,"[~"]*",[0-9-]*
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not
[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,[0-9-]*

Combine it all into one big one:
[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,("[^"]*")|([A-Za-z0-9 ]*),[0-9-]*

Any character in "A-Za-z0-9 "
* (zero or more times)
,
Any character in "A-Za-z0-9 "
* (zero or more times)
,
Capture
"
Any character not in """
* (zero or more times)
"
End Capture
or
Capture
Any character in "A-Za-z0-9 "
* (zero or more times)
End Capture
,
Any character in "0-9-"
* (zero or more times)

(Interpretation via Regular Expression Workbench)
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

<dl> wrote in message news:eT******** ******@TK2MSFTN GP15.phx.gbl... Hi

I need to write one regex to read all the fields from the following lines / file format
line 1 - some_alphanumer ic,some_alphanu meric,"somethin g,
something",numb ers_hyphenatedO Rnot
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not

At first I thought this one will do
"[^"\r\n]*",|[A-Za-z0-9 ]*,|[0-9]*\-[0-9]*

but I am getting the delimiters such as the trailing comma and the
double-quote along with the fields !!

Can this be modified to get the fields only, or at least to get rid of the
trailing comma?

TIA
--

Nov 17 '05 #2
Hi Curran

Thanks.
With some minor changes, I get a much cleaner one (compare to the one I
originally had)
[A-Za-z0-9 -]*,|("[^"]*"),|[0-9 ()-]*
but I have one question
1. there is still trialing comma, I guess we can't get rid of it, and just
have to trim it off, right?

TIA

"James Curran" <ja*********@mv ps.org> wrote in message
news:ey******** ********@TK2MSF TNGP14.phx.gbl. ..
line 1 - some_alphanumer ic,
[A-Za-z0-9 ]*,

some_alphanumer ic,
[A-Za-z0-9 ]*,

"something, something",
"[~"]*",

numbers_hyphena tedORnot
[0-9-]*

All together: [A-Za-z0-9 ]*,[A-Za-z0-9 ]*,"[~"]*",[0-9-]*
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not


[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,[0-9-]*

Combine it all into one big one:
[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,("[^"]*")|([A-Za-z0-9 ]*),[0-9-]*

Any character in "A-Za-z0-9 "
* (zero or more times)
,
Any character in "A-Za-z0-9 "
* (zero or more times)
,
Capture
"
Any character not in """
* (zero or more times)
"
End Capture
or
Capture
Any character in "A-Za-z0-9 "
* (zero or more times)
End Capture
,
Any character in "0-9-"
* (zero or more times)

(Interpretation via Regular Expression Workbench)
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

<dl> wrote in message news:eT******** ******@TK2MSFTN GP15.phx.gbl...
Hi

I need to write one regex to read all the fields from the following lines /
file format
line 1 - some_alphanumer ic,some_alphanu meric,"somethin g,
something",numb ers_hyphenatedO Rnot
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not

At first I thought this one will do
"[^"\r\n]*",|[A-Za-z0-9 ]*,|[0-9]*\-[0-9]*

but I am getting the delimiters such as the trailing comma and the
double-quote along with the fields !!

Can this be modified to get the fields only, or at least to get rid of

the trailing comma?

TIA
--


Nov 17 '05 #3
instead of the last * use a + which means "count bigger than one" so that
the comma should disappear.
<dl> schrieb im Newsbeitrag news:uL******** ******@TK2MSFTN GP15.phx.gbl...
Hi Curran

Thanks.
With some minor changes, I get a much cleaner one (compare to the one I
originally had)
[A-Za-z0-9 -]*,|("[^"]*"),|[0-9 ()-]*
but I have one question
1. there is still trialing comma, I guess we can't get rid of it, and just
have to trim it off, right?

TIA

"James Curran" <ja*********@mv ps.org> wrote in message
news:ey******** ********@TK2MSF TNGP14.phx.gbl. ..
line 1 - some_alphanumer ic,


[A-Za-z0-9 ]*,

some_alphanumer ic,
[A-Za-z0-9 ]*,

"something, something",
"[~"]*",

numbers_hyphena tedORnot
[0-9-]*

All together: [A-Za-z0-9 ]*,[A-Za-z0-9 ]*,"[~"]*",[0-9-]*
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not


[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,[0-9-]*

Combine it all into one big one:
[A-Za-z0-9 ]*,[A-Za-z0-9 ]*,("[^"]*")|([A-Za-z0-9 ]*),[0-9-]*

Any character in "A-Za-z0-9 "
* (zero or more times)
,
Any character in "A-Za-z0-9 "
* (zero or more times)
,
Capture
"
Any character not in """
* (zero or more times)
"
End Capture
or
Capture
Any character in "A-Za-z0-9 "
* (zero or more times)
End Capture
,
Any character in "0-9-"
* (zero or more times)

(Interpretation via Regular Expression Workbench)
--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

<dl> wrote in message news:eT******** ******@TK2MSFTN GP15.phx.gbl...
Hi

I need to write one regex to read all the fields from the following lines
/
file format
line 1 - some_alphanumer ic,some_alphanu meric,"somethin g,
something",numb ers_hyphenatedO Rnot
line 2 - some_alphanumer ic,some_alphanu meric,something
something,numbe rs_hyphenatedOR not

At first I thought this one will do
"[^"\r\n]*",|[A-Za-z0-9 ]*,|[0-9]*\-[0-9]*

but I am getting the delimiters such as the trailing comma and the
double-quote along with the fields !!

Can this be modified to get the fields only, or at least to get rid of

the trailing comma?

TIA
--



Nov 17 '05 #4

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

Similar topics

1
4167
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make regular expressions easier to create and use (and in my experience as a regular expression user, it makes them MUCH easier to create and use.) I'm still working on formal documentation, and in any case, such documentation isn't necessarily the...
2
1466
by: hillcountry74 | last post by:
Hi, I'm stuck with this regular expression from past 2 days. Desperately need help. I need a regular expression that will allow all characters except these *:~<>' This is my code in VB.Net- Dim regex As System.Text.RegularExpressions.Regex
4
5149
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following testMyColumn{1, 100}Test Basically I want the regular expression to add the word test infront of the
2
2938
by: VSK | last post by:
Hi all, I have a .ascx file with dropdownbox (SSN, EmpName) textbox submit button regular expression validator( controltovalidate is the above textbox) Now i want to change the Regular Expression of the validator based on the
3
1662
by: Lisa Bogart | last post by:
I am trying to take a string and parse it out into multiple strings based on a pattern but am stuck and am hoping someone can give me a clue. My pattern looks like so: sMatch = "\d\d\d\d-\d\d-\d\d\s\d\d:\d\d\sby\s<a class=link href=" & Chr(34) & "javascript:jsOpen*" What I want is to take a single string and for anything that starts with a date/time and "<a class=link href=" & Chr(34) &
7
3818
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
2
1392
by: kieran | last post by:
Hi, I am using Visual Studio 2005 and am trying to use a Regular Expression Validator control. I have a drop down list which contains various names, the first one is "Please Select". I want the user to have to select a name other than 'Please Select'. I am thinking maybe the Regular Expression Validator is the best move
25
5147
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
6
2877
by: sk.rasheedfarhan | last post by:
Hi , I am using regular expression in C++ code, . Negation is not working in the down loaded code. matches all characters except "a", "b", and "c] So I am in dilemma can negation work in C++ code. If negation works in C++ code, can any one give me a sample code, That will be benefit for me.
1
2106
by: sunil | last post by:
Hi, Am writing one C program for one of my module and facing one problem with the regular expression functions provided by the library libgen.h in solaris. In this library we are having two functions to deal with the regular expressions char *regcmp(const char *string1, /* char *string2 */ ,
0
8420
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
8324
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
8842
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
8740
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
7353
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
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
1733
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.