REGEX for CUSIP followed by two numbers.

B

Brent

I'm trying to write a regex to find this pattern

1. A 6-10 character "word" having at least one number (0-9) in any
position. It will have a space on its right side, but may have any
character on the left. In addition, when the word is nine characters --
the usual case -- it may be formatted as follows: "AAAAAA AA A".

2. White space of some length.

3. A number of some length, or the world "CALL" or "PUT".

4. White space of some length.

5. A number of some length that may have any character on its right
edge, though mostly white space.

The regex I've used so far gets about 80-90% of what I'm looking for.

The problem comes in making sure the 6-10 initial word contains at least
one number somewhere in its length. I don't know how to specify that.

I'm hoping for some fine tuning from smarter guys than I! Here is my
current expression broken out:

1. (?<CUSIP>\w\d{2}\w{6}\s|\d\w{5-10}\s|\w{6}\s\w{2}\s\w\s)
2. (\s*?)
3. (?<Value>\b\d+\b|CALL|PUT)
4. (\s*?)
5. (?<Shs_prn_amt>\b\d+)(.*?)

Many thanks for any help!

--Brent
 
T

Tom.PesterDELETETHISSS

Hi Brent,

What you need is "positive lookahead". More info here : http://www.regular-expressions.info/lookaround.html

The following regex

(?=.*\d).{6,10}

Applied to

abcdefgh
abc2efgh
abcdefgh

Will only match line 2

I dont know all the details about your input so I'll leave the total solution
to you.

Let me know how it goes.

Cheers,
Tom Pester
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top