473,503 Members | 1,953 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_alphanumeric,some_alphanumeric,"something,
something",numbers_hyphenatedORnot
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot

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 1441
> line 1 - some_alphanumeric,

[A-Za-z0-9 ]*,

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

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

numbers_hyphenatedORnot
[0-9-]*

All together: [A-Za-z0-9 ]*,[A-Za-z0-9 ]*,"[~"]*",[0-9-]*
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot
[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**************@TK2MSFTNGP15.phx.gbl... Hi

I need to write one regex to read all the fields from the following lines / file format
line 1 - some_alphanumeric,some_alphanumeric,"something,
something",numbers_hyphenatedORnot
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot

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*********@mvps.org> wrote in message
news:ey****************@TK2MSFTNGP14.phx.gbl...
line 1 - some_alphanumeric,
[A-Za-z0-9 ]*,

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

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

numbers_hyphenatedORnot
[0-9-]*

All together: [A-Za-z0-9 ]*,[A-Za-z0-9 ]*,"[~"]*",[0-9-]*
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot


[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**************@TK2MSFTNGP15.phx.gbl...
Hi

I need to write one regex to read all the fields from the following lines /
file format
line 1 - some_alphanumeric,some_alphanumeric,"something,
something",numbers_hyphenatedORnot
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot

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**************@TK2MSFTNGP15.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*********@mvps.org> wrote in message
news:ey****************@TK2MSFTNGP14.phx.gbl...
line 1 - some_alphanumeric,


[A-Za-z0-9 ]*,

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

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

numbers_hyphenatedORnot
[0-9-]*

All together: [A-Za-z0-9 ]*,[A-Za-z0-9 ]*,"[~"]*",[0-9-]*
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot


[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**************@TK2MSFTNGP15.phx.gbl...
Hi

I need to write one regex to read all the fields from the following lines
/
file format
line 1 - some_alphanumeric,some_alphanumeric,"something,
something",numbers_hyphenatedORnot
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot

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
4155
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...
2
1455
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...
4
5098
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...
2
2933
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...
3
1642
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 =...
7
3794
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...
2
1387
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...
25
5128
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...
6
2866
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++...
1
2090
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...
0
7205
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,...
0
7093
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...
0
7287
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,...
0
7467
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...
0
5592
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,...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1519
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 ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
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...

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.