![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Regexp for two words Topic Summary: Created On: 10-Sep-2007 17:14 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() 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" | |
![]() |
|
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.
|
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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"? |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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. |
|
![]() |
|
![]() |
|
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 |
|
![]() |
|
![]() |
|
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" Edited: 10-Sep-2007 at 23:27 by jason haury |
|
![]() |
|
![]() |
|
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.
|
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Regexp for two words
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.