need regular expression for stock list

B

billsahiker

I am using the following to validate user input of a comma delimited
list of stock symbols, separated by a comma and one or two spaces:

^(?:\u0020{1,2})?\w{1,5}(?:\u0020{1,2})?(?:,(?:\u0020{1,2})?\w{1,5}(?:
\u0020{1,2})?)*$

It works, but I need to allow stock indices, which begin with ^ (ascii
94). How can I do that?

sample input:

MSFT, INTC,^DJI,LU, SIRI

bill
 
B

billsahiker

I figured it out:

^(?:\u0020{1,2})?\^?\w{1,5}(?:\u0020{1,2})?(?:,(?:\u0020{1,2})?\^?
\w{1,5}(?:\u0020{1,2})?)*$

but could someone explain what the colon represents? I found a regex
reference but the colon is not listed.
 
R

ron.h.hall

I figured it out:

^(?:\u0020{1,2})?\^?\w{1,5}(?:\u0020{1,2})?(?:,(?:\u0020{1,2})?\^?
\w{1,5}(?:\u0020{1,2})?)*$

but could someone explain what the colon represents? I found a regex
reference but the colon is not listed.

It seems that is should be possible to simplify the expression
substantially by removing the requirement for lookahead (?:), along
the lines of:

/^\^?\w{1,5}(,\s{0,2}\^?\w{1,5})*$/

Note that the expression above allows for the case where there are no
spaces(tabs, etc.) following the ",", as per the example data that was
provided.
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top