Regular expression help

M

Manish Hatwalne

I am trying few things with regular expression, I would like to allow
following characters, how do I do this?
N
N-N
N+
N-
N,N

wher N is a digit.

TIA,
- Manish
 
V

Virgil Green

Manish Hatwalne said:
I am trying few things with regular expression, I would like to allow
following characters, how do I do this?
N
N-N
N+
N-
N,N

wher N is a digit.

The first thing I'd do if learning regex is download the free (for
non-commercial use) Regex Coach at http://www.weitz.de/regex-coach/

I'm unsure of your question, though. Do you want to allow any of those
patterns in a string?

- Virgil
 
M

Manish Hatwalne

Thanks a ton for regex-coach link!!!

I sort of figured it out (with some help from friends), and got thisone
which works for single comma, I am just looking for a small modification
that will work for multiple commas.

This is what I have, which works for single comma
[0-9]+[-+,]?[0-9]*

My valid strings would be -

1234
1234+
1234-
1234-5678
123,456,789
123,456

I'd prefer if I could get the pattern that I have got a bit modified so as
to work for my multiple comms requiement.

TIA,
- Manish
 
C

Chris Smith

Manish said:
I am trying few things with regular expression, I would like to allow
following characters, how do I do this?
N
N-N
N+
N-
N,N

wher N is a digit.

Looks to me like:

[0-9]([\-\+\,]([0-9])?)?

That's assuming you also want to allow "N+N" and "N,". If not, please
be more clear about what you want. (Or is it *just* the list above? in
which case "[0-9]((\,[0-9])|\+|(\-[0-9]?))?" looks like it might work.)

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Alan Moore

Thanks a ton for regex-coach link!!!

I sort of figured it out (with some help from friends), and got thisone
which works for single comma, I am just looking for a small modification
that will work for multiple commas.

This is what I have, which works for single comma
[0-9]+[-+,]?[0-9]*

My valid strings would be -

1234
1234+
1234-
1234-5678
123,456,789
123,456

I'd prefer if I could get the pattern that I have got a bit modified so as
to work for my multiple comms requiement.

\d+(\+|-\d*|(,\d+)+)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top