![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Regular Expression help Topic Summary: Created On: 2-Jun-2005 16:08 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
I am writing a script which pulls anything within double brackets out of an object and puts it into a separate object. Currently I have the following regular expression:
Regexp info = regexp ".*(({{Information ![]() It works ok, except if there is a return within the brackets. I want to modify the expression, possible so that it will capture all information within the brackets even if there is a carriage return. Any help on how to do this would be appreciated. |
|
![]() |
|
![]() |
|
I am getting slightly closer. If there is only one "new line" character in the object, then this code works, however if there are multiple "new line" characters, the text is not moved. Any ideas on how to change this code to account for multiple new lines?
|
|
![]() |
|
![]() |
|
You could strip out the carriage returns first. Here is a function to help with that:
//------------------------------------------------------------------------ string strip(string src, char toStrip) //------------------------------------------------------------------------ { Buffer orig = create Buffer stripped = create int i orig = src for (i=0; i < length(orig); i++) { if (orig != toStrip) { stripped += orig } } src = stringOf(stripped) delete(orig) delete(stripped) return(src) } So then you would do something like: string myString = "{{blahblah\n}}" myString = strip(myString, '\r') myString = strip(myString, '\n') if (info myString) { ... } You need to strip \r in addition to \n, since Windows uses \r\n for carriage return line feed. FYI: RegExp only matches up to a line feed. You cannot match \n in a RegExp. ------------------------- Shawn Stepper shawn.e.stepper@wellsfargo.com Edited: 2-Jun-2005 at 18:46 by Shawn Stepper |
|
![]() |
|
![]() |
|
Hi Michael, Try the following, it copes with newlines too. ------------------------- Regards, Richard Good |
|
![]() |
|
![]() |
|
Richard's solution would not work if there was a single ')' within the string, prior to the '))' e.g. if Test = "dfgsdfgdsfhdfjh((some info\n\nsome more stuff (some in brackets) and some more.))". This is because the square brackets in a regexp delimit a list of alternative single characters to match, so doubling up the \\)\\) is the same as a single \\). I would go for Shawn's approach.
|
|
![]() |
|
![]() |
|
Paul is quite correct in his observation. You could try the following regexp instead though it also has drawbacks, as it won't work if your module contains any "~"'s and it always breaks out at the last "))" not the first, bit of a frig really.
Regexp info = regexp "\\(\\(([^~]*)\\)\\)" The attached code provides an alternate approach ------------------------- Regards, Richard Good |
|
![]() |
|
![]() |
|
Thanks everyone for the suggestions. I'm going to test all of these options out and see what works best for my situation.
|
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Regular Expression help
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.