![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: HELP! Need ReqExpr function Topic Summary: Created On: 4-Aug-2004 15:08 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() Answer: Hi Louie, here's one. I've done a little testing and it seems to be OK. Let me know if you find anything that breaks it. Cheers, Antonio. | |
![]() |
|
Anybody write the attached function for me?
Thanks. - Louie |
|
![]() |
|
![]() |
|
Hi Louie,
here's one. I've done a little testing and it seems to be OK. Let me know if you find anything that breaks it. Cheers, Antonio. |
|
![]() |
|
![]() |
|
Oh...use the following version if "WSTR-0" or "WSTR-01" etc. is illegal.
|
|
![]() |
|
![]() |
|
Sorry, but forgot to point out that the instring would START with the format, but may contain additional characters. Your function works for "WSTR_1234" but not for "WSTR_1234 xxxx". I notice we can overflow with a huge number DoIt("WSTR_12345678901234567890") and get "1" for the result.
I think the RegExpr needs a "and zero or more random characters" at the end. What's that look like? - Louie |
|
![]() |
|
![]() |
|
Louie,
You really are going to have to get your head around regular expressions... ![]() To do the extra bit you want, change: Regexp wStr = regexp "(^WSTR[ _-])([0-9]+$)" into: Regexp wStr = regexp "(^WSTR[ _-])([0-9]+)([^0-9]|$)" The '^' as the first character in square brackets [] negates the content. So [0-9] matches any digit, and [^0-9] matches anything except a digit. The following '+' means 'one or more' (a '*' means zero or more). If the '^' is at the start of the expression, it matches the start of the string, and the '$' at the end matches the end of the string. Surrounding lumps of the expression with parentheses makes them available to the 'match' perm after the expression has been applied. The parentheses also allow you to select alternatives, separated by '|' -- the new bit means 'match anything that is either not a digit or is the end of the string'. So in your expression, you use match 0 to get the whole match, match 1 to get the WSTR plus trailing character, match 2 to get the string of digits, and match 3 to get the character after the digits, or the end of the string if there is nothing after the digits. And that completes the crash course in regular expressions. For more information (and confusion ![]() Maybe you should check the length of the string of digits before you try to convert it to an int? That would give you a clue as to whether it's going to be too big. What you do after that is up to you, of course... Paul. ------------------------- Paul dot Tiplady at TRW dot com TRW Automotive |
|
![]() |
|
![]() |
|
Also note that that test you used is a 20 digit number... that is slightly past the 32 bit int limit even if it was unsigned (2^32 being 4294967296 which is a tad shorter than 20 digits). In this case, I would just keep the number as a string and use string comparisons, unless you need to do math with it... in which case it would be a bit harder.
And Paul, your solution did not take into account the space that is required after the number (since WSTR_1324xxxx isn't supposed to work, but WSTR_1234 xxxx is). A slight modification would fix this: Regexp wStr = regexp "(^WSTR[ _-])([0-9]+)( [^0-9]+|$)" However this is a possibility that number may occur in the text string after that in which case I would use Regexp wStr = regexp "(^WSTR[ _-])([0-9]+)( [\001-\177]+|$)" Which would match any character between 001 and 177 ascii octal (why does DXL use octal?). Note this will also force "WSTR_1234 " to fail (just change the + to * if you want to keep it) Edited: 5-Aug-2004 at 13:44 by Alan Wong |
|
![]() |
|
![]() |
|
That seemed to do it, thanks.
"You really are going to have to get your head around regular expressions... " Yup. But its one of those brain-dead quirks; I just don't get it. And I have RTFM (or RTBM for the Britts or RTDarnM for the Baptists), where "F" and "B" are the key words. But I do know how to pronounce "Worcestershire Sauce" and once beat the world record in elbow coin snatching. And while I cannot spell regular words nor remember people's names, I can spell their last names more often than most folks. Don't know why, but that's the way it is. Limitations are not so bad if you acknowlege them. Besides, I answer a lot of folks questions here and a lot of folks are eager to answer mine. And since I know you guys can do this there is no particular reason for me beat my head against the wall trying to figure it out. - Louie |
|
![]() |
|
![]() |
|
Regular expressions are pretty vital to know for many reasons... mainly that computer science uses them so much, and it would benefit any coder to know it. Since dxl regex is rather lacking (doesn't have ?, and there is only * and + and not variable repetition) you should try another language to play with regex. Perl would be a place to start, or if you are more comfortable with c you can try the perl regex for c library.
For any text manipulation, regex is necessary (since who really wants to use c style string functions and if ladders?). |
|
![]() |
|
![]() |
|
That may explain my dozens of string manipulation functions that I've written for my own use: fIsSubString, ifIsPrefix, fIsSuffix, fStripPrefix, fGetBaseName, fGetPathName, fIsInFolder, fReplaceChar, fReplaceString, yaddy yaddy. But ReqExpr just seems to be one of those black holes in my head.
I cannot figure out when to wear a coat and when not to, and cannot get a grip on ReqExp. But I can find Waldo in less than a minute and may be the paper-maze champion of the world. Or not. ![]() - Louie |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
HELP! Need ReqExpr function
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.