JRockFL
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='[^']+'" );
<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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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,@"titl e=""[^""]* ""","");
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,@"titl e=""[^""]* ""","");
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?
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,@"titl
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,@"titl
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?
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?
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?
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
A superb book is "Mastering Regular Expressions", Jeffrey E. F. Friedl, published by O'Reilly, ISBN 0-596-00289-0
ASKER
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