Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions problem (again)

Status
Not open for further replies.

ktucci

Programmer
Apr 23, 2001
146
US
does anyone know of any easy way using regular expressions to parse out these fields, i will be evaluating one line at time..below are some examples of the lines i will be evaluating

this is the desired output i wish to get for each line even if they dont have data in the fields

phone#,qty,code,detail,datecode,date,amount

----------------------------------------------------
here are some examples of the source data, not all have the required fields, but will need to be accounted for using a coma
-----------------------------------------------------

2122060409, 1 POR2X /TN 212 206-0409 I 03-17-99 0.23

2122060409, 1 ALN /TN 212 206-0952/LPIC NYC /LPCX 0698/LPCA DB, 10-09-00 /PIC WTL/PICX 0555 /PCA CN, 11-15-00 T 05-02-97 14.23

2122060409, 1 POR2X /TN 212 206-0952 I 03-17-99 0.23 HTG 1 206-0404-0407 I

2122060409, 1 RXR /CX 212 206-0404/HTG 1 /CAT 3 /CTX 0327/LCC N9I /CN 01 /LPIC NYC/LPCX 0698 /LPCA DB, 10-09-00 /PIC WTL /PICX 0555/PCA CN, 11-15-00 T 05-02-97

2122060409, 1 EABDF /CX 212 206-0404/MWC * MWCH1 T 04-08-97

2122060409, 1 EABDF /CX 212 206-0404/MWC * MWCH1
 
Easy!

1. Read all of it in as a String, then
2. Get the position of the first separator, " "
in this case - use InStr(), then
3. Successively use InStr() to locate all the remaining
" ", then
4. Repeatedly use Mid() to copy portions of the parent
string that occur between two " ".
 
thanks, but i am trying to parse this string using regular expressions...so far i got:

re.Pattern = "\s+(\d+)\s+(\w+)\s+(/.*?)\s+(\s{1}\w{1}\s{1,}(.*))"

Set Matches1 = re.Execute(Match.SubMatches(0))
j = 0
For Each Match1 In Matches1
Set Match1 = Matches1(j)
j = j + 1
MsgBox strbtn & "," & Match1.SubMatches(1) & "," & Match1.SubMatches(0) & "," & Match1.SubMatches(2) & "," & Match1.SubMatches(3)
'Call SaveTextFile(str_export & str_filename & ".txt", strbtn & "," & Match1.SubMatches(1) & "," & Match1.SubMatches(0) & "," & Match1.SubMatches(2))
Next
 
If I am reading your pattern correctly (not a given by any means) then you're matching for

1 or more spaces
1 or more digits (save it)
1 or more spaces
1 or more alpha characters (save it)
1 or more spaces
forwardslash any char 0 or more times, - not sure what the ? is doing (save it)
1 or more spaces
exactly one space
exactly one character
at least 1 s
any number of chars (save it)

and saving the last items.

I'm not sure, like you, just getting my feet wet with RE, but I don't think you'll match anywhere because you asking for at least a leading space

I would try starting the pattern with \s* instead of \s+
I am not sure about the ? in (/.*?)
and I am not too sure about s+(\s{1} - 1 or more spaces followed by exacly one space?

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
CajunCenturion

ill try that...thanks for your help

keith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top