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: Regexp for two words
Topic Summary:
Created On: 10-Sep-2007 17:14
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.
Answer This question was answered by jason haury, on Tuesday, September 11, 2007 12:38 AM

Answer:

It sounds like you are trying to check a string to see if the word "message" and the word "video" appear in the same string, is that correct? If so, you might need to use two regular expressions in the event you don't care about what order those words come in. If they have come in a certain order then you'll need to use just 1 regexp. see attached code =)

Also, in a regexp, a "." means any character except a newline, and a "+" means one or more instances of whatever you put before it (a character, range of chars in [square brackets], or a match string in (parenthesis).  the "+" is a lot like "*" except there has to be at least one instance of the preceding string.  In the vidMessRE regexp in my code, the ".+" means there has to be at least one of any character between the words "video" and "message".  This will exclude a compound word like "videomessage" but will accept a string like "it's fun to put a video in a message!".  If you want to allow words like "videomesage" to be valid, but still force "message" to come after "video", then simply replace my "+" with a "*" to make the regexp "video.*message"

Jason

 10-Sep-2007 17:14
User is offline View Users Profile Print this message


Krishna Kandala

Posts: 170
Joined: 8-Jul-2006

Hi All,

I am trying to use the Regexp for the AND function of two words. I have the following code and results. I would like to know how to use this function correct.
Thanks in advance.

 

 



 

Report this to a Moderator Report this to a Moderator
 10-Sep-2007 18:15
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

Hi Krishna,

the * at end of your expression says, that video can occour zero or any times.
So it is correct to match first string the match appears on message only.
In second test, no "message" is in string so the one, or more + does not match.
In third string "message" appears and video matches zero times.

Greetings
Reik

-------------------------
Evosoft GmbH
for Siemens Industry Sector


Berlin, Germany
Report this to a Moderator Report this to a Moderator
 10-Sep-2007 18:41
User is offline View Users Profile Print this message


Krishna Kandala

Posts: 170
Joined: 8-Jul-2006

Hi Reik,

Do we consider that zero is included in "any number of times"? That is strange - how can I modify this function to exclude zero from "any number of times"?
Report this to a Moderator Report this to a Moderator
 10-Sep-2007 19:54
User is offline View Users Profile Print this message


Kevin Murphy

Posts: 206
Joined: 15-Jul-2005

Krishna,

Regexp str1 = regexp "(message)+(video).*"

This ought to work. The .* means match at least one occurrence.

-------------------------
Kevin Murphy
http://www.baselinesinc.com
The Requirements Management Experts
Report this to a Moderator Report this to a Moderator
 10-Sep-2007 21:46
User is offline View Users Profile Print this message


Krishna Kandala

Posts: 170
Joined: 8-Jul-2006

Hi Kevin,
I tried what you suggested. i.e (video)+(message).* Now it does not show any output. This should print the test string in the first instance.
Report this to a Moderator Report this to a Moderator
 10-Sep-2007 22:06
User is offline View Users Profile Print this message


Kevin Murphy

Posts: 206
Joined: 15-Jul-2005

Krishna,

What exactly are you trying to do?

From your original post, it seems to me like you were asking why "You have a message" is printing a false match, even though there is no video. Reik explained that video is matching 0 or more times.

Are you wanting a true on the first string and a false on the other strings?

If so, then this is what you want:

Regexp str1 = regexp "(video)+.(message)"

If this is NOT what you want, give examples of what you want to match vs. what you do not want to match and I'm sure we can figure something out.

-------------------------
Kevin Murphy
http://www.baselinesinc.com
The Requirements Management Experts
Report this to a Moderator Report this to a Moderator
 10-Sep-2007 23:21
User is offline View Users Profile Print this message


jason haury

Posts: 39
Joined: 20-Feb-2007

Answer Answer

It sounds like you are trying to check a string to see if the word "message" and the word "video" appear in the same string, is that correct? If so, you might need to use two regular expressions in the event you don't care about what order those words come in. If they have come in a certain order then you'll need to use just 1 regexp. see attached code =)

Also, in a regexp, a "." means any character except a newline, and a "+" means one or more instances of whatever you put before it (a character, range of chars in [square brackets], or a match string in (parenthesis).  the "+" is a lot like "*" except there has to be at least one instance of the preceding string.  In the vidMessRE regexp in my code, the ".+" means there has to be at least one of any character between the words "video" and "message".  This will exclude a compound word like "videomessage" but will accept a string like "it's fun to put a video in a message!".  If you want to allow words like "videomesage" to be valid, but still force "message" to come after "video", then simply replace my "+" with a "*" to make the regexp "video.*message"

Jason



Edited: 10-Sep-2007 at 23:27 by jason haury
Report this to a Moderator Report this to a Moderator
 11-Sep-2007 00:38
User is offline View Users Profile Print this message


Krishna Kandala

Posts: 170
Joined: 8-Jul-2006

Thanks, Jason and Kevin, for a detailed explanation of the various ".", "+" and "*" functions. The explanation in the DXL manual, as usual, is cursory and difficult to understand.
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 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 2 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.