473,378 Members | 1,429 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,378 software developers and data experts.

REGEX for CUSIP followed by two numbers.

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
Nov 19 '05 #1
1 1963
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
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

Nov 19 '05 #2

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

Similar topics

4
by: Fazer | last post by:
Hello, I have a string which has a url (Begins with a http://) somewhere in it. I want to detect such a url and just spit out the url. Since I am very poor in regex, can someone show me how to...
2
by: Mr.Clean | last post by:
I am working on modifying a syntax highlighter written in javascript and it uses several regexes. I need to add a language to the avail highlighters and need the following regexes modified to...
2
by: Morten Snedker | last post by:
In another thread I found this snippet for validating an e-mail: ^(+)@((\{1,3}\.{1,3}\.{1,3}\.)|((+\.)+))({2,4}|{1,3})(\]?)$ Would someone please help to read this? I don't get the slashes,...
5
by: skavan | last post by:
Hi, I'm just wrapping my head around regex and am pretty sure it can do the task at hand - but it's too complex for my brain to process -- so am throwing it out there for you experts to comment...
5
by: Al | last post by:
Hi, I have the following code : string sData=@"{\*\bkmkstart adresse1} FORMTEXT }{\rtlch \af0 \ltrch \f1\fs22\insrsid16733897\charrsid10567516 {\*\datafield...
1
by: TumurS | last post by:
Hi! I need to parse an input string. The string must consist of 1, 2 or 3 float numbers separated with blanks: Regex r = new Regex(@"^\s*(?<x>+)(\s+(?<y>+)(\s+(?<z>+))*)*\s*$",...
11
by: proctor | last post by:
hello, i have a regex: rx_test = re.compile('/x()*x/') which is part of this test program: ============ import re
7
by: Nightcrawler | last post by:
Hi all, I am trying to use regular expressions to parse out mp3 titles into three different groups (artist, title and remix). I currently have three ways to name a mp3 file: Artist - Title ...
3
by: Praveen | last post by:
looking for regex pattern for validating emailid emailid can have a-z 0-9 - _ . (a to z, 0 ot 9, hyphen,undercore, dot) here is a sample which I got from net which doesnt allow hyphen(-) ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.