DOORS regex - backreferences not possible?

Hi,

just wondering about the regular expression find/replace in DOORS:

I'm not sure about the regex flavor of DOORS. But for me it seems that regex backreferences (as \1 ... \9) are not possible. Maybe someone knows more??

Thanks a lot!

phil
SystemAdmin - Thu Nov 12 13:32:06 EST 2009

Re: DOORS regex - backreferences not possible?
SystemAdmin - Thu Nov 12 13:33:24 EST 2009

Of course a version always helps ... We're using DOORS 8.2.0.2

Re: DOORS regex - backreferences not possible?
SystemAdmin - Fri Nov 13 07:05:03 EST 2009

Look up Regular expressions in the DXL Help. Has a list of supported expressions and info regarding the use of Regexp in DXL coding.

/Kristian

Re: DOORS regex - backreferences not possible?
llandale - Fri Nov 13 13:08:10 EST 2009

Back reference? Are you asking to search for the string backslash-digit, looks like \9? If so, use double slash in the regexp
Regexp reSlashDigit = regexp("\[0-9]") I think.

  • Louie

Re: DOORS regex - backreferences not possible?
doors36677 - Sat Nov 14 11:17:41 EST 2009

To retrieve your pattern match, use:

int start(int n)
int end(int n)

Re: DOORS regex - backreferences not possible?
SystemAdmin - Mon Nov 16 07:48:59 EST 2009

Thanks a lot for your hints. The problem we have is a bit different, however:

If you got a grouped (bracketed) expression e.g. like "(Item No .*)" you can - at least in most regex flavors - backtrace to the grouped matches the regex engine has found by using "\1" for the first match, "\2" for the second, ...

http://www.regular-expressions.info/brackets.html

This would be a convenient tool for a search / replace e.g. in a numbered list.

Re: DOORS regex - backreferences not possible?
SystemAdmin - Mon Nov 16 08:57:35 EST 2009

SystemAdmin - Mon Nov 16 07:48:59 EST 2009
Thanks a lot for your hints. The problem we have is a bit different, however:

If you got a grouped (bracketed) expression e.g. like "(Item No .*)" you can - at least in most regex flavors - backtrace to the grouped matches the regex engine has found by using "\1" for the first match, "\2" for the second, ...

http://www.regular-expressions.info/brackets.html

This would be a convenient tool for a search / replace e.g. in a numbered list.

You could find all matches and put them in a skip list and find them there...

Regexp REXP = regexp2 
"(yes[0-9])" string str = 
"noyes1yes2yes3yes4no" Skip slMatches = create 

int loop = 0 

int noMatches = 0   

while (REXP str) 
{ loop++ put (slMatches, loop, str[match 1]) str = str[end (1) + 1:] 
} noMatches = loop loop = 1 

while (find (slMatches, loop, str)) 
{ print loop 
" - " str 
"\n" loop++ 
} delete (slMatches)


/Kristian

Re: DOORS regex - backreferences not possible?
Peter_Albert - Mon Nov 16 09:16:12 EST 2009

SystemAdmin - Mon Nov 16 08:57:35 EST 2009
You could find all matches and put them in a skip list and find them there...


Regexp REXP = regexp2 
"(yes[0-9])" string str = 
"noyes1yes2yes3yes4no" Skip slMatches = create 

int loop = 0 

int noMatches = 0   

while (REXP str) 
{ loop++ put (slMatches, loop, str[match 1]) str = str[end (1) + 1:] 
} noMatches = loop loop = 1 

while (find (slMatches, loop, str)) 
{ print loop 
" - " str 
"\n" loop++ 
} delete (slMatches)


/Kristian

If you want to refer to grouped options, identified by brackets in the regular expression, you can just use the 'match ' perm as described in the DXL Help:


Regexp URL = regexp 
"(HTTP|http|ftp|FTP|file|FILE)://([^  \\),;>\
"]*)" string txt3 = 
"The ABC URL is http://www.abc.com; it may be..." 

if (URL txt3) 
{ print txt3[match 0] 
"\n"    
// whole match  print txt3[match 1] 
"\n"    
// first section in ()  print txt3[match 2] 
"\n"    
// second section in ()  
}


Of course this is not what the previous poster proposed, so depending on your actual demands you might use one way or the other.

Regards,

Peter

Re: DOORS regex - backreferences not possible?
SystemAdmin - Tue Nov 24 04:07:01 EST 2009

Peter_Albert - Mon Nov 16 09:16:12 EST 2009
If you want to refer to grouped options, identified by brackets in the regular expression, you can just use the 'match ' perm as described in the DXL Help:


Regexp URL = regexp 
"(HTTP|http|ftp|FTP|file|FILE)://([^  \\),;>\
"]*)" string txt3 = 
"The ABC URL is http://www.abc.com; it may be..." 

if (URL txt3) 
{ print txt3[match 0] 
"\n"    
// whole match  print txt3[match 1] 
"\n"    
// first section in ()  print txt3[match 2] 
"\n"    
// second section in ()  
}


Of course this is not what the previous poster proposed, so depending on your actual demands you might use one way or the other.

Regards,

Peter

Thanks again for your hints - seems there's quite a lot of DXL know-how available.

However, as I have very limited DXL scripting experience, my intention was just to use the "old-school" CTRL-F Find & Replace function with regex backreferences in the replace field. I understood that this is just not implemented in DOORS.

Folks, thank you!