I've got a problem parsing the Paragraph Style attribute using regular expressions. It is almost certainly due to my limited experience with regular expressions but have been unable to find an answer either in the DOORS forums or on other sites that explain regular expressions. pragma runLim, 100000 int count = 0 string str1 = "<Attributes:bold><Object Text:Body Text><Verification Method:italic>" Regexp re1 = regexp2 "(<.*>)" while(re1 str1){ count ++ print count " " str1[match 1] "\n" str1 = str1[end (1) + 1:] print "new string: " str1 "\n" }
Regexp re1 = regexp2 "(<.*>)(<.*>)
The output becomes: bmij - Thu Mar 29 11:21:27 EDT 2012 |
Re: Paragraph Style attribute parsing with regular expressions I think that will result in you doing this:
-Louie |
Re: Paragraph Style attribute parsing with regular expressions llandale - Thu Mar 29 11:50:57 EDT 2012
-Louie You should do this: Buffer buf = create(); buf = "<a:bc><d:fg><e:hg>" Regexp reg = regexp2 "<([^>]+):([^>]+)>" int pos = 0 while (search(reg, buf, pos)) { // ... process matches... string sAttr = buf[pos+(start 1):pos+(end 1)] string sStyle = buf[pos+(start 2):pos+(end 2)] print "Attribute: " sAttr " Style: " sStyle "\n" pos += 1 + end 0 }
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Paragraph Style attribute parsing with regular expressions Mathias Mamsch - Thu Mar 29 14:23:33 EDT 2012 You should do this: Buffer buf = create(); buf = "<a:bc><d:fg><e:hg>" Regexp reg = regexp2 "<([^>]+):([^>]+)>" int pos = 0 while (search(reg, buf, pos)) { // ... process matches... string sAttr = buf[pos+(start 1):pos+(end 1)] string sStyle = buf[pos+(start 2):pos+(end 2)] print "Attribute: " sAttr " Style: " sStyle "\n" pos += 1 + end 0 }
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thank you for that code. It provides me a good start for what I'm trying to achieve. The built in 'Edit Paragraph Style attribute' function does the job most of the time but if there are one or two objects, typically headings, that need the style changing the issue is finding the object with the wrong style. For example a heading has been demoted from level 3 to level 4. The required style is <Object Heading:Heading 4> but the actual value is <Object Heading:Heading 3>. I've written a few lines of DXL that checks every object but it does not handle cases where the attribute has multiple entries. Your example will allow me to correct that. Jim |
Re: Paragraph Style attribute parsing with regular expressions |