473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

regular expression for comma-delimited pairs

I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]\s?\"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"
Any suggestions would be appreciated.
Feb 13 '07 #1
5 2248
Bosconian wrote:
I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]\s?\"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"
Any suggestions would be appreciated.

Try the /s modifier. Perhaps a bit "tipsy" to examine the regex in depth.

Curtis
Feb 13 '07 #2
On 13 Feb, 04:06, "Bosconian" <nob...@nowhere.comwrote:
I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]\s?\"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"

Any suggestions would be appreciated.
The ? following [0-9] means that
"","John" will also be matched.
Also, the * before the $ means that
"1" will be matched
So at the very least you want
^"[0-9]+"([,]\s?\"([A-Za-z0-9]+)")$
Since a $ means "the end of the line" and since a carriage return
signifies the end of a line, his should do. Or do you want to ensure
that there is a carriage return at theend, even if there is only one
line?

Feb 13 '07 #3
"Captain Paralytic" <pa**********@yahoo.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
On 13 Feb, 04:06, "Bosconian" <nob...@nowhere.comwrote:
>I have a textarea form field for inputting (or pasting) pairs of data.

I need a regular expression pattern to validate each line for the
following

double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return

The following comes close, but doesn't check for a carriage return at the
end of each line:

^"([0-9]?)+"([,]\s?\"([A-Za-z0-9]+)")*$

For example the following would return true:

"1","John"
"2","Paul"
"3","George"
"4","Ringo"

Any suggestions would be appreciated.

The ? following [0-9] means that
"","John" will also be matched.
Also, the * before the $ means that
"1" will be matched
So at the very least you want
^"[0-9]+"([,]\s?\"([A-Za-z0-9]+)")$
Since a $ means "the end of the line" and since a carriage return
signifies the end of a line, his should do. Or do you want to ensure
that there is a carriage return at theend, even if there is only one
line?
Thank you for your response and for the pattern corrections.

A trailing carriage return on the last line would be unnecessary and ignored
if present. However, any preceding pairs must have a carriage return at the
end of each line. Where in the pattern is this mandated?

I don't have the opportunity to use regular expressions consistency, but I
am anxious to learn the syntax and am grateful for your instruction.
Feb 13 '07 #4
On 13 Feb, 13:36, "Bosconian" <nob...@nowhere.comwrote:
"Captain Paralytic" <paul_laut...@yahoo.comwrote in message

news:11**********************@s48g2000cws.googlegr oups.com...


On 13 Feb, 04:06, "Bosconian" <nob...@nowhere.comwrote:
I have a textarea form field for inputting (or pasting) pairs of data.
I need a regular expression pattern to validate each line for the
following
double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return
The following comes close, but doesn't check for a carriage return at the
end of each line:
^"([0-9]?)+"([,]\s?\"([A-Za-z0-9]+)")*$
For example the following would return true:
"1","John"
"2","Paul"
"3","George"
"4","Ringo"
Any suggestions would be appreciated.
The ? following [0-9] means that
"","John" will also be matched.
Also, the * before the $ means that
"1" will be matched
So at the very least you want
^"[0-9]+"([,]\s?\"([A-Za-z0-9]+)")$
Since a $ means "the end of the line" and since a carriage return
signifies the end of a line, his should do. Or do you want to ensure
that there is a carriage return at theend, even if there is only one
line?

Thank you for your response and for the pattern corrections.

A trailing carriage return on the last line would be unnecessary and ignored
if present. However, any preceding pairs must have a carriage return at the
end of each line. Where in the pattern is this mandated?

I don't have the opportunity to use regular expressions consistency, but I
am anxious to learn the syntax and am grateful for your instruction.- Hide quoted text -

- Show quoted text -
If you are treating each line as a separate string, then the $ will
indicate this. If you are treating all the lines as a single string
then I need to ask, is it only a carriage return that you will have at
the end of each line and all you want to check for? Sometimes lines
can be ended by a carriage return and a new line (\r\n) \nd sometimes
by a new line only (\n). It is unusual for a line to have only a
carriage return on its own (\r) as, on older printers, this would lead
to the next line overtyping the previous one.

Feb 13 '07 #5
"Captain Paralytic" <pa**********@yahoo.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
On 13 Feb, 13:36, "Bosconian" <nob...@nowhere.comwrote:
>"Captain Paralytic" <paul_laut...@yahoo.comwrote in message

news:11**********************@s48g2000cws.googleg roups.com...


On 13 Feb, 04:06, "Bosconian" <nob...@nowhere.comwrote:
I have a textarea form field for inputting (or pasting) pairs of data.
>I need a regular expression pattern to validate each line for the
following
>double quote
number
double quote
comma
double quote
alpha string
double quote
carriage return
>The following comes close, but doesn't check for a carriage return at
the
end of each line:
>^"([0-9]?)+"([,]\s?\"([A-Za-z0-9]+)")*$
>For example the following would return true:
>"1","John"
"2","Paul"
"3","George"
"4","Ringo"
>Any suggestions would be appreciated.
The ? following [0-9] means that
"","John" will also be matched.
Also, the * before the $ means that
"1" will be matched
So at the very least you want
^"[0-9]+"([,]\s?\"([A-Za-z0-9]+)")$
Since a $ means "the end of the line" and since a carriage return
signifies the end of a line, his should do. Or do you want to ensure
that there is a carriage return at theend, even if there is only one
line?

Thank you for your response and for the pattern corrections.

A trailing carriage return on the last line would be unnecessary and
ignored
if present. However, any preceding pairs must have a carriage return at
the
end of each line. Where in the pattern is this mandated?

I don't have the opportunity to use regular expressions consistency, but
I
am anxious to learn the syntax and am grateful for your instruction.-
Hide quoted text -

- Show quoted text -

If you are treating each line as a separate string, then the $ will
indicate this. If you are treating all the lines as a single string
then I need to ask, is it only a carriage return that you will have at
the end of each line and all you want to check for? Sometimes lines
can be ended by a carriage return and a new line (\r\n) \nd sometimes
by a new line only (\n). It is unusual for a line to have only a
carriage return on its own (\r) as, on older printers, this would lead
to the next line overtyping the previous one.
Yes, I assume we're talking about \n or \r\n.

Incidentally, I would like to support several methods of entry. My idea is
to have the user select a radio button for the format. For example,
optionally the user could input

1,John
2,Paul
3,George
4,Ringo

1,John,2,Paul,3,George,4,Ringo

I eventually want it to work the same was as phpMyAdmin's import feature.
However, this will be used by non-tech savvy users so validation will play
an important part.

Again, thanks for your help.
Feb 13 '07 #6

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

Similar topics

0
by: amazononthemoon | last post by:
I have not been able to find any examples of the type of validation I need. I have numeric fields on a web page that I only want them to enter numbers with two decimal places. I would like to...
1
by: Sue | last post by:
Hello I'm new to this Regular Expression and need some help. I want to restrict what the user types in a text box. The User can type only A-Z, a-z, 0-9, spaces, comma, dash, period, single...
3
by: Jorell | last post by:
Hi everyone. I have never worked with regular expressions before and here is my dillema: I have a textbox that I want to only accept this type of input: 1,2,3-8,10,16 ( Comma separated...
1
by: | last post by:
Hi, I have a Regular Expression that will match the format a user provides in a textbox. Ex. Brown,Joe in the textbox I would like the expression to have both whitespace and...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
3
by: LordHog | last post by:
Hello all, I am attempting to create a small scripting application to be used during testing. I extract the commands from the script file I was going to tokenize the each line as one of the...
10
by: samuelberthelot | last post by:
Hi, I'd like to use regular expression for checking validity of a field. What would be the expression for : firstname, lastname, organisation23 so basically, a string + comma then another...
7
by: hellbent4u | last post by:
Hi All, I need a regular expression to be used in an ASP page which would allow a user to enter: 1000 as well as 1,000 i.e. an amount without comma as well as with comma(for example 10,000...
5
by: shawnmkramer | last post by:
Anyone every heard of the Regex.IsMatch and Regex.Match methods just hanging and eventually getting a message "Requested Service not found"? I have the following pattern: ^(?<OrgCity>(+)+),...
7
by: graphicsxp | last post by:
Hi, I can't figure out what the regular expression would look like for validating a string such as : Lastname, Firstname I could only come up with /\w/ which doesn't check for the comma. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...
0
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,...

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.