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: Matching strings
Topic Summary: Incorrect matching of a substring
Created On: 18-Aug-2005 22:58
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 Paul Tiplady, on Friday, August 19, 2005 3:20 PM

Answer:
I think it's a simple one: regular expressions treat '.' as 'match any character'. You need to escape the '.' to match an actual period. So swap your line:

Regexp line1 = regexp fig_string1"([0-9]+)(.|-)([0-9]+)(.)([0-9]+)\\b"

for

Regexp line1 = regexp fig_string1"([0-9]+)(\.|-)([0-9]+)(\.)([0-9]+)\\b"

and it should work as you expect.

Paul.
 18-Aug-2005 22:58
User is offline View Users Profile Print this message


Brian Jackson

Posts: 10
Joined: 2-Aug-2005

I'm trying to match a substring in a string but keep getting incorrect matching results. My code looks like the following:
--------------------------------------------------------------
Object o
string attrName = "Object Text" // This is the attribute to search
string fig_string1 = "Figure "

Regexp line1 = regexp fig_string1"([0-9]+)(.|-)([0-9]+)(.)([0-9]+)\\b"

 for o in current Module do
   {
     s1 = o.attrName ""
     if (line1 s1)
     {
      <some DXL code>
     }
   }
--------------------------------------------------------------
Basically, I'm trying to match text that looks something like "Figure 2-237.1" for example. But, when I run the script, it matches sample substrings like "Figure 2-56" when it parses through a module. I'm not interested in that. I'm only interested in formats that look like "Figure x-y.z" not "Figure x-y" (where x, y, and z represent integers). Suggestions?

Report this to a Moderator Report this to a Moderator
 19-Aug-2005 08:52
User is offline View Users Profile Print this message


Paul Tiplady

Posts: 176
Joined: 28-Oct-2003

Answer Answer
I think it's a simple one: regular expressions treat '.' as 'match any character'. You need to escape the '.' to match an actual period. So swap your line:

Regexp line1 = regexp fig_string1"([0-9]+)(.|-)([0-9]+)(.)([0-9]+)\\b"

for

Regexp line1 = regexp fig_string1"([0-9]+)(\.|-)([0-9]+)(\.)([0-9]+)\\b"

and it should work as you expect.

Paul.

-------------------------


Paul dot Tiplady at TRW dot com
TRW Automotive
Report this to a Moderator Report this to a Moderator
 19-Aug-2005 15:19
User is offline View Users Profile Print this message


Brian Jackson

Posts: 10
Joined: 2-Aug-2005

I see what you mean. When I took your suggestion, I received a "badly formed token" error. But, when I (\\.) instead of (\.), it worked fine. Thanks for pointing me in the right direction, Paul.
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.