Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Regular Expression help
Topic Summary:
Created On: 2-Jun-2005 16:08
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 2-Jun-2005 16:08
User is offline View Users Profile Print this message


Michael Venos

Posts: 20
Joined: 26-May-2004

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.
Report this to a Moderator Report this to a Moderator
 2-Jun-2005 18:42
User is offline View Users Profile Print this message


Michael Venos

Posts: 20
Joined: 26-May-2004

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?
Report this to a Moderator Report this to a Moderator
 2-Jun-2005 18:44
User is offline View Users Profile Print this message


Shawn Stepper

Posts: 96
Joined: 6-Aug-2004

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
Report this to a Moderator Report this to a Moderator
 3-Jun-2005 18:21
User is offline View Users Profile Print this message


Richard Good

Posts: 152
Joined: 22-Mar-2005

Hi Michael,

Try the following, it copes with newlines too.



-------------------------
Regards,

Richard Good
Report this to a Moderator Report this to a Moderator
 6-Jun-2005 08:40
User is offline View Users Profile Print this message


Paul Worrall

Posts: 87
Joined: 30-Sep-2003

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.
Report this to a Moderator Report this to a Moderator
 6-Jun-2005 17:07
User is offline View Users Profile Print this message


Richard Good

Posts: 152
Joined: 22-Mar-2005

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
Report this to a Moderator Report this to a Moderator
 9-Jun-2005 13:17
User is offline View Users Profile Print this message


Michael Venos

Posts: 20
Joined: 26-May-2004

Thanks everyone for the suggestions. I'm going to test all of these options out and see what works best for my situation.
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.