Link to home
Start Free TrialLog in
Avatar of JRockFL
JRockFLFlag for United States of America

asked on

RegEx Help

How can I remove title="http://www.test.com" ?
<a title="http://www.test.com" href="http://www.test.com">test</a>

Desired results
<a  href="http://www.test.com">test</a>

It needs to be a RegEx, this is only one example of many different titles

The current code I am using removes some styles and classes, I need to add something that will remove the titles
           // Get rid of classes and styles
            sc.Add(@"\s?class=\w+");
            sc.Add(@"\s+style='[^']+'");  
ASKER CERTIFIED SOLUTION
Avatar of josgood
josgood
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JRockFL

ASKER

Thanks for your reply. I should of explained better. I need to remove all occurences
of
title="http://www.test.com"
anything that starts with title and ends with the second "
www.test.com was a generic example, i will be parsing hundreds of urls
OK, you want to remove title="anything".  That's what I intended the example to do.

I did a quick cut-and-paste
         string start = @"<a title=""http://www.test.com"" href=""http://www.test.com"">test</a>";
         string want  = @"<a  href=""http://www.test.com"">test</a>";
         string result = Regex.Replace(start,@"title=""[^""]*""","");
         Console.WriteLine(start);
         Console.WriteLine(result);
         start = @"<a title=""Regular Expressions can be fun"" href=""Have a nice day"">test</a>";
         result = Regex.Replace(start,@"title=""[^""]*""","");
         Console.WriteLine(start);
         Console.WriteLine(result);

which produces
<a title="http://www.test.com" href="http://www.test.com">test</a>
<a  href="http://www.test.com">test</a>
<a title="Regular Expressions can be fun" href="Have a nice day">test</a>
<a  href="Have a nice day">test</a>

Am I misunderstanding what you want?
Avatar of JRockFL

ASKER

I'm sorry, it was my fault. You understood me correctly.
One last thing, can you translate this into english for me so I have a better undestanding of it.
@"title=""[^""]*"""
Also, can you recommned any RegEx referrences?
Avatar of JRockFL

ASKER

Nevermind, I see your explanation. Thank you. It's too early!
No problem.

A superb book is "Mastering Regular Expressions", Jeffrey E. F. Friedl, published by O'Reilly, ISBN 0-596-00289-0