From: Paul Lutus Date: 2006-12-13T19:50:13+09:00 Subject: Re: Restricted capture in Regexp benjohn@fysh.org wrote: / ... > thanks for the reply. I know I can do this, but it means that the > substitution ("\\1\\2\\3") has to be aware of the composition of the > regular expression. Yes, that is true for all regular expressions. > The Regexp is no longer a neat little machine that > only grabs things to replace. It's now grabbing the packaging around the > thing to replace too, so you've got to be aware of this in writing the > substitution. Yes, but this cannot be avoided. You have two choices for examined text that surrounds the area to be modified -- you can capture it while examining it, and use the captured text in the replacement, or you can use non-capturing references: (?=non-captured text) But the two alternatives work much the same way -- they examine text that is preserved as part of the overall regular expression. All that changes is /how/ the text is preserved. So, to move ahead, please post a specific example of what you need. Post an example of the original string and the desired replacement. It is scarcely possible to describe in prose what one wants from a regular expression. It /is/ possible to take a first step by posting an example of original text, and replacement text. Maybe we should try that. -- Paul Lutus http://www.arachnoid.com