By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

need regular expression for stock list

P: n/a
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})?(?:,(?:\u0 020{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

Jun 14 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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.

Jun 14 '07 #2

P: n/a
On Jun 14, 11:34 am, billsahi...@yahoo.com wrote:
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.
--
../rh

Jun 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.