![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Best Parsing Practices To Follow Topic Summary: Created On: 6-Jun-2008 20:16 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
I took one of my old PERL programmers that parses a string of integers from a list of comma separated list of integers. When I attempted to convert this code into DXL I am running into some problems.
Here is some sample code I put together: string x = "342,525,562662,6266,66223" Regexp magic = regexp "^[0-9]*+(,[0-9]+)+$" if (magic x) { print x[match 0] "\n" } Running this code (in DOORS 7.1) generates this error message. -R-E- DXL: <Line:4> incorrect regular expression (re_search) -I- DXL: execution halted I'm not that concern about the error message at the moment but in general, should I be using strictly Buffers over Regular Expressions when parsing data? I once read somewhere that Regular Expressions are another memory leak. For the example I have given the variable x has 6 different numbers. Is there a DXL command that will parse the complete string or Buffer value when you don't know beforehand the amount of items that the string or Buffer contains? Thanks. ------------------------- pete.kowalski(at)motorola.com |
|
![]() |
|
![]() |
|
I personally don't like regular expressions, probably 'cause I don't use them all that much. Here's what I do which prints the following:
342 525 562662 6266 66223 ------------------------- Scott Boisvert Engineering Tools Administrator L-3 Communications - Avionics Systems scott.boisvert@l-3com.com Edited: 6-Jun-2008 at 20:28 by Scott Boisvert |
|
![]() |
|
![]() |
|
Yes, regular expressions are always very cryptic. Not to metion, each language implements them slightly different.
Basically, you don't need the plusses "+", and you need a way to loop through all the matches. The code below will print out each value. Edit: You could make this function more useful by passing it the string. See cbTest2 below. Now you can have something like: string x1 = "123,456,789,1011,1213" string x2 = "1415,1617,1819,2021" cbTest2(x1) cbTest2(x2) Edited: 6-Jun-2008 at 21:33 by David Jakad |
|
![]() |
|
![]() |
|
Scott,
Thanks for your clean and easy to follow code. Never knew it was this easy. A million of thanks ------------------------- pete.kowalski(at)motorola.com |
|
![]() |
|
![]() |
|
David,
I used PERL extensively for years so I have learned to master the art of writing and understanding cryptic regular expressions. I learned recently that now there are interactive tools out there that makes this less of a burden on the end-user but personally I still enjoy just using notepad to write and debug my expressions. I am taking time to look at your code. Thanks for the sample. It seems to me intially that you will know beforehand how many numbers are in "x1" or "x2" before you are able parse each number out. Wait, nevermind. I just ran the code and see how it works now. It's quite useful. Thanks for the education lesson. ------------------------- pete.kowalski(at)motorola.com |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Best Parsing Practices To Follow
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.