ignatiusst
asked on
Regular Expression - replace pattern with another pattern
I am working in C#, and I am trying to replace the brackets on an html tag. For example, I want to change <ul type='square'> to <ul type='square'>
With the Regex.Replace, I can find the pattern (<ul(\s+type\s*=\s*(?:""(d isc|circle |square)"" |'(disc|ci rcle|squar e)'|(disc| circle|squ are)))?\s* >), but is there any way to replace with another patter (eg: <ul(\s+type\s*=\s*(?:""( disc|circl e|square)" "|'(disc|c ircle|squa re)'|(disc |circle|sq uare)))?\s *>)?
With the Regex.Replace, I can find the pattern (<ul(\s+type\s*=\s*(?:""(d
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am curious ... is there something wrong with using HTTPutility.HtmlEncode which will do just this?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassHtmlEncodeTopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebHttpServerUtilityClassHtmlEncodeTopic.asp
ASKER
exoska - thanks! sorry it took so long to get back... I just copied the replacement string you provided (<$1>), and it took me a bit of trouble-shooting to realize you had also enclosed everything inside the tags in parenthesis...
amit_g - two minutes earlier, and... :)
gregoryyoung - thanks for the link! This might be what I am looking for (I do like trying to figure these things out on my own before I use a packaged solution.. call me sick... :) ), though I am only interested in a sub-set of valid HTML - if I receive (for example) <table>, I want to leave it as-is... I will have to investigate whether the HtmlEncode can handle this.
amit_g - two minutes earlier, and... :)
gregoryyoung - thanks for the link! This might be what I am looking for (I do like trying to figure these things out on my own before I use a packaged solution.. call me sick... :) ), though I am only interested in a sub-set of valid HTML - if I receive (for example) <table>, I want to leave it as-is... I will have to investigate whether the HtmlEncode can handle this.
oh i m glad :)
<(ul(\s+type\s*=\s*(?:""(d
and use replacement string
<$1>