View Single Post
Old 07-15-2008   #4 (permalink)
Old Pedant


 
 

Re: regular expressions to replace but keep character?

"ekkehard.horner" wrote:
Quote:

>
> oRE.Pattern = "(<)(\s*)(\S+)(\s*)(>)"
> 1 2 3 4 5
> sRes = oRE.Replace( "< br >", "$1$3$5" )
>
You can do it a lot simpler than that.

oRE.Pattern = "<\s*([^\s>]+)\s*>"
sRes = oRE.Replace( "< br >", "<$1>" )

Since you *KNOW* that you are looking for <...> and you *KNOW* you want to
retain <...>, just do *NOT* put any of that stuff in the parentheses. So now
only the non-space, non-> characters will be in parens and there's only one
"group" to be plunked into the output.

My System SpecsSystem Spec