Yet another Regular Expressions question..

vcvc

Active member
Joined
Nov 14, 2003
Messages
27
I have an app that performs a great deal of parsing of existing ASCII text files. Its running fine using various string manipulation gymnastics. Obviously there are scenarios where regular expressions will work better, but Im having a hard time getting my head around the required cerebral contortions that regular expressions require. eg
I have a a text file (in a different language - DMIS) that may declare variable in a number of different ways. I would like to extract the variable names from the text for later use.
The code could appear anywhere in the file as any of the following:
DECL/REAL, var1, var2, var2
or
DECL/REAL,GLOBAL, var1, var2, var3
or
DECL/REAL,COMMON, var1, var2,var3
etc etc
This is probably simple the RegEx gurus
Any suggetions to extract the variable names using regular expressions would be welcomed!
 
could you post some example lines of the contents of the files? I mean with the data as it will really look like. thats important to see which characters could appear in the different sections - until now you could only use the "," as the seperator character. but to make it work in all cases I have to be sure that the "," wont appear in any data-entries....
 
Heres a quick little snippet:

DECL/REAL,X1,Y1,Z1,I1,J1,K1,X2,Y2,Z2,I2,J2
DECL/GLOBAL,DOUBLE,B1,B10,B11,B12,B13,B14
DECL/COMMON,INTGR,NUM_SCANS,MAX_PTS,SCAN_DIR,LOOP_VAL

I would like to use regular expressions instead of string gymnastics to get the variable names to add to an array. Add all the REALs to one array, add all the DOUBLEs to another array etc etc.

Thanks
 
Thanks! Ill check it out tonight.
Im looking forward to cleaning up all my ugly string manipulation!
 
Thanks for the effort! Very usefull code after I rebuilt it in vs2002 (sorry, dont have the money for the new toys).

Unfortunatley you got bit by the same thing I was fighting with.
In the sample below, the scope "GLOBAL" or "COMMON" may or maynot exist depending on the scope the user requires.
DECL/REAL,X1,Y1,Z1,I1,J1,K1,X2,Y2,Z2,I2,J2
DECL/GLOBAL,DOUBLE,B1,B10,B11,B12,B13,B14
DECL/COMMON,INTGR,NUM_SCANS,MAX_PTS,SCAN_DIR,LOOP_VAL
In the language used above the syntax is:
DECL/opt_1, opt2,varname(s)
where opt_1 can be
GLOBAL or COMMON or LOCAL or nothing
and opt2 is the variable type REAL or DOUBLE etc etc

In the 1st line(DECL/REAL) there is no scope applied, in the 2nd and 3rd lines different scopes (DECL/GLOBAL and DECL/COMMON)
I need to remove the scope (if any) from the variable names.

I am doing this now with strings as I am VERY weak on regular expressions.
Im sure reg ex can handle this "may or maynot" scenario and Im sure the answer is right in front of me - I just cant see the forest for the trees.
 
see the attached project... I updated it to make it fit your needs... btw. you could have that earlier if youd answered my question for the format of the data correctly when I first asked... anyway... this version should do the trick!

Andreas
 

Attachments

Thanks so much for the example!!!
I have played with the example, took it apart and put it back together a number of different ways.
That is exactly what I needed to better understand!
It now makes sense!

Heres to ya Hamburger. **raising a glass of whiskey**
Youve been a great help!
vc
 
vcvc said:
Thanks so much for the example!!!
I have played with the example, took it apart and put it back together a number of different ways.
That is exactly what I needed to better understand!
It now makes sense!

Heres to ya Hamburger. **raising a glass of whiskey**
Youve been a great help!
vc
Thanks! [Broken External Image]:http://www.computerhelp.forum/images/smilies/wink.gif

Glad that I could help you.. If youve got further questions - as always...: just ask!

Andreas
 
Back
Top